This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new e2df2ee632 Use InputStream::readAllBytes
e2df2ee632 is described below
commit e2df2ee632b440239feaeb75c8fe18b4f8507d92
Author: Matt Sicker <[email protected]>
AuthorDate: Sun Jul 31 17:40:34 2022 -0500
Use InputStream::readAllBytes
Signed-off-by: Matt Sicker <[email protected]>
---
.../log4j/core/config/ConfigurationSource.java | 47 ++++++----------------
1 file changed, 12 insertions(+), 35 deletions(-)
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
index 24f7961625..66680f197c 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
@@ -17,8 +17,18 @@
package org.apache.logging.log4j.core.config;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.AuthorizationProvider;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.core.util.Loader;
+import org.apache.logging.log4j.core.util.Source;
+import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
+
+import javax.net.ssl.HttpsURLConnection;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -33,19 +43,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
-import org.apache.logging.log4j.core.net.UrlConnectionFactory;
-import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
-import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
-import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
-import org.apache.logging.log4j.core.util.AuthorizationProvider;
-import org.apache.logging.log4j.core.util.FileUtils;
-import org.apache.logging.log4j.core.util.Loader;
-import org.apache.logging.log4j.core.util.Source;
-import org.apache.logging.log4j.util.LoaderUtil;
-import org.apache.logging.log4j.util.PropertiesUtil;
-
-import javax.net.ssl.HttpsURLConnection;
-
/**
* Represents the source for the logging configuration.
*/
@@ -146,7 +143,7 @@ public class ConfigurationSource {
* @throws IOException if an exception occurred reading from the specified
stream
*/
public ConfigurationSource(final InputStream stream) throws IOException {
- this(toByteArray(stream), null, 0);
+ this(stream.readAllBytes(), null, 0);
}
public ConfigurationSource(final Source source, final byte[] data, final
long lastModified) throws IOException {
@@ -168,26 +165,6 @@ public class ConfigurationSource {
}
}
- /**
- * Returns the contents of the specified {@code InputStream} as a byte
array.
- *
- * @param inputStream the stream to read
- * @return the contents of the specified stream
- * @throws IOException if a problem occurred reading from the stream
- */
- private static byte[] toByteArray(final InputStream inputStream) throws
IOException {
- final int buffSize = Math.max(4096, inputStream.available());
- final ByteArrayOutputStream contents = new
ByteArrayOutputStream(buffSize);
- final byte[] buff = new byte[buffSize];
-
- int length = inputStream.read(buff);
- while (length > 0) {
- contents.write(buff, 0, length);
- length = inputStream.read(buff);
- }
- return contents.toByteArray();
- }
-
/**
* Returns the file configuration source, or {@code null} if this
configuration source is based on an URL or has
* neither a file nor an URL.