This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit b9e4f5e6e718ec8e4156e31bef733874700d7cbf Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Apr 12 12:33:12 2023 -0400 Bump default buffer size to IOUtils#DEFAULT_BUFFER_SIZE - Bump default buffer size for CharSequenceInputStream to IOUtils#DEFAULT_BUFFER_SIZE. - Bump default buffer size for ChunkedOutputStream to IOUtils#DEFAULT_BUFFER_SIZE. - Bump default buffer size for ChunkedWriter to IOUtils#DEFAULT_BUFFER_SIZE. - Bump default buffer size for ReaderInputStream to IOUtils#DEFAULT_BUFFER_SIZE. - Bump default buffer size for WriterOutputStream to IOUtils#DEFAULT_BUFFER_SIZE. --- src/changes/changes.xml | 15 ++++++++++++ .../commons/io/input/CharSequenceInputStream.java | 11 ++++----- .../apache/commons/io/input/ReaderInputStream.java | 28 ++++++++++------------ .../io/input/buffer/PeekableInputStream.java | 4 +++- .../commons/io/output/ChunkedOutputStream.java | 4 +++- .../apache/commons/io/output/ChunkedWriter.java | 4 +++- .../commons/io/output/WriterOutputStream.java | 3 ++- .../commons/io/output/ChunkedOutputStreamTest.java | 3 ++- .../commons/io/output/ChunkedWriterTest.java | 5 +++- 9 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e68f4a6a..687777f1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -544,6 +544,21 @@ The <action> type attribute can be add,update,fix,remove. <action dev="kinow" type="update" due-to="Dependabot"> Bump apache-rat-plugin from 0.14 to 0.15 #387. </action> + <action dev="ggregory" type="update" due-to="Gary Gregory"> + Bump default buffer size for CharSequenceInputStream to IOUtils#DEFAULT_BUFFER_SIZE. + </action> + <action dev="ggregory" type="update" due-to="Gary Gregory"> + Bump default buffer size for ChunkedOutputStream to IOUtils#DEFAULT_BUFFER_SIZE. + </action> + <action dev="ggregory" type="update" due-to="Gary Gregory"> + Bump default buffer size for ChunkedWriter to IOUtils#DEFAULT_BUFFER_SIZE. + </action> + <action dev="ggregory" type="update" due-to="Gary Gregory"> + Bump default buffer size for ReaderInputStream to IOUtils#DEFAULT_BUFFER_SIZE. + </action> + <action dev="ggregory" type="update" due-to="Gary Gregory"> + Bump default buffer size for WriterOutputStream to IOUtils#DEFAULT_BUFFER_SIZE. + </action> </release> <release version="2.11.0" date="2021-07-09" description="Java 8 required."> <!-- FIX --> diff --git a/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java b/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java index 6fe6d9e8..38686f69 100644 --- a/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java +++ b/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java @@ -31,6 +31,7 @@ import java.nio.charset.CodingErrorAction; import java.util.Objects; import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; /** * Implements an {@link InputStream} to read from String, StringBuffer, StringBuilder or CharBuffer. @@ -42,8 +43,6 @@ import org.apache.commons.io.Charsets; */ public class CharSequenceInputStream extends InputStream { - private static final int BUFFER_SIZE = 2048; - private static final int NO_MARK = -1; private final CharsetEncoder charsetEncoder; @@ -54,14 +53,14 @@ public class CharSequenceInputStream extends InputStream { private int bBufMark; // position in bBuf /** - * Constructs a new instance with a buffer size of 2048. + * Constructs a new instance with a buffer size of {@link IOUtils#DEFAULT_BUFFER_SIZE}. * * @param cs the input character sequence. * @param charset the character set name to use. * @throws IllegalArgumentException if the buffer is not large enough to hold a complete character. */ public CharSequenceInputStream(final CharSequence cs, final Charset charset) { - this(cs, charset, BUFFER_SIZE); + this(cs, charset, IOUtils.DEFAULT_BUFFER_SIZE); } /** @@ -87,14 +86,14 @@ public class CharSequenceInputStream extends InputStream { } /** - * Constructs a new instance with a buffer size of 2048. + * Constructs a new instance with a buffer size of {@link IOUtils#DEFAULT_BUFFER_SIZE}. * * @param cs the input character sequence. * @param charset the character set name to use. * @throws IllegalArgumentException if the buffer is not large enough to hold a complete character. */ public CharSequenceInputStream(final CharSequence cs, final String charset) { - this(cs, charset, BUFFER_SIZE); + this(cs, charset, IOUtils.DEFAULT_BUFFER_SIZE); } /** diff --git a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java index 88c7d3e1..2eb92226 100644 --- a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java +++ b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java @@ -30,6 +30,7 @@ import java.nio.charset.CodingErrorAction; import java.util.Objects; import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; import org.apache.commons.io.charset.CharsetEncoders; /** @@ -81,7 +82,6 @@ import org.apache.commons.io.charset.CharsetEncoders; * @since 2.0 */ public class ReaderInputStream extends InputStream { - private static final int DEFAULT_BUFFER_SIZE = 1024; static int checkMinBufferSize(final CharsetEncoder charsetEncoder, final int bufferSize) { final float minRequired = minBufferSize(charsetEncoder); @@ -116,8 +116,8 @@ public class ReaderInputStream extends InputStream { private boolean endOfInput; /** - * Constructs a new {@link ReaderInputStream} that uses the default character encoding with a default input buffer size - * of {@value #DEFAULT_BUFFER_SIZE} characters. + * Constructs a new {@link ReaderInputStream} that uses the default character encoding with a default input buffer size of + * {@value IOUtils#DEFAULT_BUFFER_SIZE} characters. * * @param reader the target {@link Reader} * @deprecated 2.5 use {@link #ReaderInputStream(Reader, Charset)} instead @@ -128,19 +128,17 @@ public class ReaderInputStream extends InputStream { } /** - * Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value #DEFAULT_BUFFER_SIZE} - * characters. + * Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value IOUtils#DEFAULT_BUFFER_SIZE} characters. * * <p> - * The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input - * and unmappable characters. + * The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input and unmappable characters. * </p> * - * @param reader the target {@link Reader} + * @param reader the target {@link Reader} * @param charset the charset encoding */ public ReaderInputStream(final Reader reader, final Charset charset) { - this(reader, charset, DEFAULT_BUFFER_SIZE); + this(reader, charset, IOUtils.DEFAULT_BUFFER_SIZE); } /** @@ -178,7 +176,7 @@ public class ReaderInputStream extends InputStream { * @since 2.1 */ public ReaderInputStream(final Reader reader, final CharsetEncoder charsetEncoder) { - this(reader, charsetEncoder, DEFAULT_BUFFER_SIZE); + this(reader, charsetEncoder, IOUtils.DEFAULT_BUFFER_SIZE); } /** @@ -204,19 +202,17 @@ public class ReaderInputStream extends InputStream { } /** - * Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value #DEFAULT_BUFFER_SIZE} - * characters. + * Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value IOUtils#DEFAULT_BUFFER_SIZE} characters. * * <p> - * The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input - * and unmappable characters. + * The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input and unmappable characters. * </p> * - * @param reader the target {@link Reader} + * @param reader the target {@link Reader} * @param charsetName the name of the charset encoding */ public ReaderInputStream(final Reader reader, final String charsetName) { - this(reader, charsetName, DEFAULT_BUFFER_SIZE); + this(reader, charsetName, IOUtils.DEFAULT_BUFFER_SIZE); } /** diff --git a/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java b/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java index 6e9b88ce..a2c55f81 100644 --- a/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java +++ b/src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Objects; +import org.apache.commons.io.IOUtils; + /** * Implements a buffered input stream, which allows to peek into the buffers first bytes. This comes in handy when * manually implementing scanners, lexers, parsers, and the like. @@ -27,7 +29,7 @@ import java.util.Objects; public class PeekableInputStream extends CircularBufferInputStream { /** - * Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size (8192). + * Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size ({@link IOUtils#DEFAULT_BUFFER_SIZE}). * * @param inputStream The input stream, which is being buffered. */ diff --git a/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java b/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java index e319454a..cb8be00d 100644 --- a/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java @@ -20,6 +20,8 @@ import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; +import org.apache.commons.io.IOUtils; + /** * OutputStream which breaks larger output blocks into chunks. * Native code may need to copy the input array; if the write buffer @@ -32,7 +34,7 @@ public class ChunkedOutputStream extends FilterOutputStream { /** * The default chunk size to use, i.e. {@value} bytes. */ - private static final int DEFAULT_CHUNK_SIZE = 1024 * 4; + private static final int DEFAULT_CHUNK_SIZE = IOUtils.DEFAULT_BUFFER_SIZE; /** * The maximum chunk size to us when writing data arrays diff --git a/src/main/java/org/apache/commons/io/output/ChunkedWriter.java b/src/main/java/org/apache/commons/io/output/ChunkedWriter.java index 409c78ed..14d36b76 100644 --- a/src/main/java/org/apache/commons/io/output/ChunkedWriter.java +++ b/src/main/java/org/apache/commons/io/output/ChunkedWriter.java @@ -20,6 +20,8 @@ import java.io.FilterWriter; import java.io.IOException; import java.io.Writer; +import org.apache.commons.io.IOUtils; + /** * Writer which breaks larger output blocks into chunks. * Native code may need to copy the input array; if the write buffer @@ -32,7 +34,7 @@ public class ChunkedWriter extends FilterWriter { /** * The default chunk size to use, i.e. {@value} bytes. */ - private static final int DEFAULT_CHUNK_SIZE = 1024 * 4; + private static final int DEFAULT_CHUNK_SIZE = IOUtils.DEFAULT_BUFFER_SIZE; /** * The maximum chunk size to us when writing data arrays diff --git a/src/main/java/org/apache/commons/io/output/WriterOutputStream.java b/src/main/java/org/apache/commons/io/output/WriterOutputStream.java index c9ab9cb3..7ccb4817 100644 --- a/src/main/java/org/apache/commons/io/output/WriterOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/WriterOutputStream.java @@ -28,6 +28,7 @@ import java.nio.charset.CodingErrorAction; import java.nio.charset.StandardCharsets; import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; import org.apache.commons.io.charset.CharsetDecoders; /** @@ -76,7 +77,7 @@ import org.apache.commons.io.charset.CharsetDecoders; * @since 2.0 */ public class WriterOutputStream extends OutputStream { - private static final int BUFFER_SIZE = 1024; + private static final int BUFFER_SIZE = IOUtils.DEFAULT_BUFFER_SIZE; /** * Check if the JDK in use properly supports the given charset. diff --git a/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java index 11eacbf1..54287add 100644 --- a/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java +++ b/src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; /** @@ -34,7 +35,7 @@ public class ChunkedOutputStreamTest { final AtomicInteger numWrites = new AtomicInteger(); try (ByteArrayOutputStream baos = newByteArrayOutputStream(numWrites); final ChunkedOutputStream chunked = new ChunkedOutputStream(baos)) { - chunked.write(new byte[1024 * 4 + 1]); + chunked.write(new byte[IOUtils.DEFAULT_BUFFER_SIZE + 1]); assertEquals(2, numWrites.get()); } } diff --git a/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java b/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java index 96e89ae1..5be01e1c 100644 --- a/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java +++ b/src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java @@ -23,9 +23,12 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; public class ChunkedWriterTest { + + @SuppressWarnings("resource") // closed by caller. private OutputStreamWriter getOutputStreamWriter(final AtomicInteger numWrites) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); return new OutputStreamWriter(baos) { @@ -60,7 +63,7 @@ public class ChunkedWriterTest { final AtomicInteger numWrites = new AtomicInteger(); try (OutputStreamWriter osw = getOutputStreamWriter(numWrites)) { try (ChunkedWriter chunked = new ChunkedWriter(osw)) { - chunked.write(new char[1024 * 4 + 1]); + chunked.write(new char[IOUtils.DEFAULT_BUFFER_SIZE + 1]); chunked.flush(); assertEquals(2, numWrites.get()); }