Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
public class BoundedStreamBufferer {

public static byte[] toByteArray(InputStream is, int bufferSize) throws IOException {
if (bufferSize <= 0) {
// buffer size cannot be zero,
// set it to 1 instead.
bufferSize = 1;
}
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
byte[] b = new byte[bufferSize];
int n;
Expand All @@ -23,6 +28,11 @@ public static byte[] toByteArray(InputStream is, int bufferSize) throws IOExcept
}

public static byte[] toByteArrayWithMarkReset(InputStream is, int bufferSize) throws IOException {
if (bufferSize <= 0) {
// buffer size cannot be zero,
// set it to 1 instead.
bufferSize = 1;
}
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
byte[] b = new byte[bufferSize];
// burn some bytes to force mark/reset
Expand Down