Skip to content

Commit b9e4f5e

Browse files
committed
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.
1 parent 58957e4 commit b9e4f5e

9 files changed

Lines changed: 49 additions & 28 deletions

File tree

src/changes/changes.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,21 @@ The <action> type attribute can be add,update,fix,remove.
544544
<action dev="kinow" type="update" due-to="Dependabot">
545545
Bump apache-rat-plugin from 0.14 to 0.15 #387.
546546
</action>
547+
<action dev="ggregory" type="update" due-to="Gary Gregory">
548+
Bump default buffer size for CharSequenceInputStream to IOUtils#DEFAULT_BUFFER_SIZE.
549+
</action>
550+
<action dev="ggregory" type="update" due-to="Gary Gregory">
551+
Bump default buffer size for ChunkedOutputStream to IOUtils#DEFAULT_BUFFER_SIZE.
552+
</action>
553+
<action dev="ggregory" type="update" due-to="Gary Gregory">
554+
Bump default buffer size for ChunkedWriter to IOUtils#DEFAULT_BUFFER_SIZE.
555+
</action>
556+
<action dev="ggregory" type="update" due-to="Gary Gregory">
557+
Bump default buffer size for ReaderInputStream to IOUtils#DEFAULT_BUFFER_SIZE.
558+
</action>
559+
<action dev="ggregory" type="update" due-to="Gary Gregory">
560+
Bump default buffer size for WriterOutputStream to IOUtils#DEFAULT_BUFFER_SIZE.
561+
</action>
547562
</release>
548563
<release version="2.11.0" date="2021-07-09" description="Java 8 required.">
549564
<!-- FIX -->

src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Objects;
3232

3333
import org.apache.commons.io.Charsets;
34+
import org.apache.commons.io.IOUtils;
3435

3536
/**
3637
* Implements an {@link InputStream} to read from String, StringBuffer, StringBuilder or CharBuffer.
@@ -42,8 +43,6 @@
4243
*/
4344
public class CharSequenceInputStream extends InputStream {
4445

45-
private static final int BUFFER_SIZE = 2048;
46-
4746
private static final int NO_MARK = -1;
4847

4948
private final CharsetEncoder charsetEncoder;
@@ -54,14 +53,14 @@ public class CharSequenceInputStream extends InputStream {
5453
private int bBufMark; // position in bBuf
5554

5655
/**
57-
* Constructs a new instance with a buffer size of 2048.
56+
* Constructs a new instance with a buffer size of {@link IOUtils#DEFAULT_BUFFER_SIZE}.
5857
*
5958
* @param cs the input character sequence.
6059
* @param charset the character set name to use.
6160
* @throws IllegalArgumentException if the buffer is not large enough to hold a complete character.
6261
*/
6362
public CharSequenceInputStream(final CharSequence cs, final Charset charset) {
64-
this(cs, charset, BUFFER_SIZE);
63+
this(cs, charset, IOUtils.DEFAULT_BUFFER_SIZE);
6564
}
6665

6766
/**
@@ -87,14 +86,14 @@ public CharSequenceInputStream(final CharSequence cs, final Charset charset, fin
8786
}
8887

8988
/**
90-
* Constructs a new instance with a buffer size of 2048.
89+
* Constructs a new instance with a buffer size of {@link IOUtils#DEFAULT_BUFFER_SIZE}.
9190
*
9291
* @param cs the input character sequence.
9392
* @param charset the character set name to use.
9493
* @throws IllegalArgumentException if the buffer is not large enough to hold a complete character.
9594
*/
9695
public CharSequenceInputStream(final CharSequence cs, final String charset) {
97-
this(cs, charset, BUFFER_SIZE);
96+
this(cs, charset, IOUtils.DEFAULT_BUFFER_SIZE);
9897
}
9998

10099
/**

src/main/java/org/apache/commons/io/input/ReaderInputStream.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Objects;
3131

3232
import org.apache.commons.io.Charsets;
33+
import org.apache.commons.io.IOUtils;
3334
import org.apache.commons.io.charset.CharsetEncoders;
3435

3536
/**
@@ -81,7 +82,6 @@
8182
* @since 2.0
8283
*/
8384
public class ReaderInputStream extends InputStream {
84-
private static final int DEFAULT_BUFFER_SIZE = 1024;
8585

8686
static int checkMinBufferSize(final CharsetEncoder charsetEncoder, final int bufferSize) {
8787
final float minRequired = minBufferSize(charsetEncoder);
@@ -116,8 +116,8 @@ static float minBufferSize(final CharsetEncoder charsetEncoder) {
116116
private boolean endOfInput;
117117

118118
/**
119-
* Constructs a new {@link ReaderInputStream} that uses the default character encoding with a default input buffer size
120-
* of {@value #DEFAULT_BUFFER_SIZE} characters.
119+
* Constructs a new {@link ReaderInputStream} that uses the default character encoding with a default input buffer size of
120+
* {@value IOUtils#DEFAULT_BUFFER_SIZE} characters.
121121
*
122122
* @param reader the target {@link Reader}
123123
* @deprecated 2.5 use {@link #ReaderInputStream(Reader, Charset)} instead
@@ -128,19 +128,17 @@ public ReaderInputStream(final Reader reader) {
128128
}
129129

130130
/**
131-
* Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value #DEFAULT_BUFFER_SIZE}
132-
* characters.
131+
* Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value IOUtils#DEFAULT_BUFFER_SIZE} characters.
133132
*
134133
* <p>
135-
* The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input
136-
* and unmappable characters.
134+
* The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input and unmappable characters.
137135
* </p>
138136
*
139-
* @param reader the target {@link Reader}
137+
* @param reader the target {@link Reader}
140138
* @param charset the charset encoding
141139
*/
142140
public ReaderInputStream(final Reader reader, final Charset charset) {
143-
this(reader, charset, DEFAULT_BUFFER_SIZE);
141+
this(reader, charset, IOUtils.DEFAULT_BUFFER_SIZE);
144142
}
145143

146144
/**
@@ -178,7 +176,7 @@ public ReaderInputStream(final Reader reader, final Charset charset, final int b
178176
* @since 2.1
179177
*/
180178
public ReaderInputStream(final Reader reader, final CharsetEncoder charsetEncoder) {
181-
this(reader, charsetEncoder, DEFAULT_BUFFER_SIZE);
179+
this(reader, charsetEncoder, IOUtils.DEFAULT_BUFFER_SIZE);
182180
}
183181

184182
/**
@@ -204,19 +202,17 @@ public ReaderInputStream(final Reader reader, final CharsetEncoder charsetEncode
204202
}
205203

206204
/**
207-
* Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value #DEFAULT_BUFFER_SIZE}
208-
* characters.
205+
* Constructs a new {@link ReaderInputStream} with a default input buffer size of {@value IOUtils#DEFAULT_BUFFER_SIZE} characters.
209206
*
210207
* <p>
211-
* The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input
212-
* and unmappable characters.
208+
* The encoder created for the specified charset will use {@link CodingErrorAction#REPLACE} for malformed input and unmappable characters.
213209
* </p>
214210
*
215-
* @param reader the target {@link Reader}
211+
* @param reader the target {@link Reader}
216212
* @param charsetName the name of the charset encoding
217213
*/
218214
public ReaderInputStream(final Reader reader, final String charsetName) {
219-
this(reader, charsetName, DEFAULT_BUFFER_SIZE);
215+
this(reader, charsetName, IOUtils.DEFAULT_BUFFER_SIZE);
220216
}
221217

222218
/**

src/main/java/org/apache/commons/io/input/buffer/PeekableInputStream.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
import java.io.InputStream;
2121
import java.util.Objects;
2222

23+
import org.apache.commons.io.IOUtils;
24+
2325
/**
2426
* Implements a buffered input stream, which allows to peek into the buffers first bytes. This comes in handy when
2527
* manually implementing scanners, lexers, parsers, and the like.
2628
*/
2729
public class PeekableInputStream extends CircularBufferInputStream {
2830

2931
/**
30-
* Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size (8192).
32+
* Creates a new instance, which filters the given input stream, and uses a reasonable default buffer size ({@link IOUtils#DEFAULT_BUFFER_SIZE}).
3133
*
3234
* @param inputStream The input stream, which is being buffered.
3335
*/

src/main/java/org/apache/commons/io/output/ChunkedOutputStream.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.IOException;
2121
import java.io.OutputStream;
2222

23+
import org.apache.commons.io.IOUtils;
24+
2325
/**
2426
* OutputStream which breaks larger output blocks into chunks.
2527
* Native code may need to copy the input array; if the write buffer
@@ -32,7 +34,7 @@ public class ChunkedOutputStream extends FilterOutputStream {
3234
/**
3335
* The default chunk size to use, i.e. {@value} bytes.
3436
*/
35-
private static final int DEFAULT_CHUNK_SIZE = 1024 * 4;
37+
private static final int DEFAULT_CHUNK_SIZE = IOUtils.DEFAULT_BUFFER_SIZE;
3638

3739
/**
3840
* The maximum chunk size to us when writing data arrays

src/main/java/org/apache/commons/io/output/ChunkedWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.IOException;
2121
import java.io.Writer;
2222

23+
import org.apache.commons.io.IOUtils;
24+
2325
/**
2426
* Writer which breaks larger output blocks into chunks.
2527
* Native code may need to copy the input array; if the write buffer
@@ -32,7 +34,7 @@ public class ChunkedWriter extends FilterWriter {
3234
/**
3335
* The default chunk size to use, i.e. {@value} bytes.
3436
*/
35-
private static final int DEFAULT_CHUNK_SIZE = 1024 * 4;
37+
private static final int DEFAULT_CHUNK_SIZE = IOUtils.DEFAULT_BUFFER_SIZE;
3638

3739
/**
3840
* The maximum chunk size to us when writing data arrays

src/main/java/org/apache/commons/io/output/WriterOutputStream.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.charset.StandardCharsets;
2929

3030
import org.apache.commons.io.Charsets;
31+
import org.apache.commons.io.IOUtils;
3132
import org.apache.commons.io.charset.CharsetDecoders;
3233

3334
/**
@@ -76,7 +77,7 @@
7677
* @since 2.0
7778
*/
7879
public class WriterOutputStream extends OutputStream {
79-
private static final int BUFFER_SIZE = 1024;
80+
private static final int BUFFER_SIZE = IOUtils.DEFAULT_BUFFER_SIZE;
8081

8182
/**
8283
* Check if the JDK in use properly supports the given charset.

src/test/java/org/apache/commons/io/output/ChunkedOutputStreamTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.util.concurrent.atomic.AtomicInteger;
2424

25+
import org.apache.commons.io.IOUtils;
2526
import org.junit.jupiter.api.Test;
2627

2728
/**
@@ -34,7 +35,7 @@ public void defaultConstructor() throws IOException {
3435
final AtomicInteger numWrites = new AtomicInteger();
3536
try (ByteArrayOutputStream baos = newByteArrayOutputStream(numWrites);
3637
final ChunkedOutputStream chunked = new ChunkedOutputStream(baos)) {
37-
chunked.write(new byte[1024 * 4 + 1]);
38+
chunked.write(new byte[IOUtils.DEFAULT_BUFFER_SIZE + 1]);
3839
assertEquals(2, numWrites.get());
3940
}
4041
}

src/test/java/org/apache/commons/io/output/ChunkedWriterTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
import java.io.OutputStreamWriter;
2424
import java.util.concurrent.atomic.AtomicInteger;
2525

26+
import org.apache.commons.io.IOUtils;
2627
import org.junit.jupiter.api.Test;
2728

2829
public class ChunkedWriterTest {
30+
31+
@SuppressWarnings("resource") // closed by caller.
2932
private OutputStreamWriter getOutputStreamWriter(final AtomicInteger numWrites) {
3033
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
3134
return new OutputStreamWriter(baos) {
@@ -60,7 +63,7 @@ public void write_two_chunks_default_constructor() throws Exception {
6063
final AtomicInteger numWrites = new AtomicInteger();
6164
try (OutputStreamWriter osw = getOutputStreamWriter(numWrites)) {
6265
try (ChunkedWriter chunked = new ChunkedWriter(osw)) {
63-
chunked.write(new char[1024 * 4 + 1]);
66+
chunked.write(new char[IOUtils.DEFAULT_BUFFER_SIZE + 1]);
6467
chunked.flush();
6568
assertEquals(2, numWrites.get());
6669
}

0 commit comments

Comments
 (0)