Skip to content

Commit 96c63d3

Browse files
committed
Internal refactoring
1 parent e15874e commit 96c63d3

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Builder() {
9393
*/
9494
@Override
9595
public ChunkedOutputStream get() throws IOException {
96-
return new ChunkedOutputStream(getOutputStream(), getBufferSize());
96+
return new ChunkedOutputStream(this);
9797
}
9898

9999
}
@@ -113,6 +113,22 @@ public static Builder builder() {
113113
*/
114114
private final int chunkSize;
115115

116+
/**
117+
* Constructs a new stream that uses the specified chunk size.
118+
*
119+
* @param builder holds contruction data.
120+
* @throws IOException if an I/O error occurs.
121+
*/
122+
@SuppressWarnings("resource") // caller closes.
123+
private ChunkedOutputStream(final Builder builder) throws IOException {
124+
super(builder.getOutputStream());
125+
final int bufferSize = builder.getBufferSize();
126+
if (bufferSize <= 0) {
127+
throw new IllegalArgumentException("chunkSize <= 0");
128+
}
129+
this.chunkSize = bufferSize;
130+
}
131+
116132
/**
117133
* Constructs a new stream that uses a chunk size of {@link IOUtils#DEFAULT_BUFFER_SIZE}.
118134
*
@@ -141,6 +157,7 @@ public ChunkedOutputStream(final OutputStream stream, final int chunkSize) {
141157
this.chunkSize = chunkSize;
142158
}
143159

160+
/* Package-private for testing. */
144161
int getChunkSize() {
145162
return chunkSize;
146163
}

0 commit comments

Comments
 (0)