Skip to content

Commit adb6d3b

Browse files
authored
fix: set bufferSize to 1 when bufferSize is less than or equal to 0 in BoundedStreamBufferer (#283)
1 parent 264168d commit adb6d3b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/test/java/software/amazon/encryption/s3/utils/BoundedStreamBufferer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
public class BoundedStreamBufferer {
1313

1414
public static byte[] toByteArray(InputStream is, int bufferSize) throws IOException {
15+
if (bufferSize <= 0) {
16+
// buffer size cannot be zero,
17+
// set it to 1 instead.
18+
bufferSize = 1;
19+
}
1520
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
1621
byte[] b = new byte[bufferSize];
1722
int n;
@@ -23,6 +28,11 @@ public static byte[] toByteArray(InputStream is, int bufferSize) throws IOExcept
2328
}
2429

2530
public static byte[] toByteArrayWithMarkReset(InputStream is, int bufferSize) throws IOException {
31+
if (bufferSize <= 0) {
32+
// buffer size cannot be zero,
33+
// set it to 1 instead.
34+
bufferSize = 1;
35+
}
2636
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
2737
byte[] b = new byte[bufferSize];
2838
// burn some bytes to force mark/reset

0 commit comments

Comments
 (0)