diff --git a/src/main/java/org/aksw/iguana/commons/io/BigByteArrayInputStream.java b/src/main/java/org/aksw/iguana/commons/io/BigByteArrayInputStream.java index 9d2efe7bb..769a26205 100644 --- a/src/main/java/org/aksw/iguana/commons/io/BigByteArrayInputStream.java +++ b/src/main/java/org/aksw/iguana/commons/io/BigByteArrayInputStream.java @@ -102,8 +102,6 @@ public int readNBytes(byte[] b, int off, int len) throws IOException { return copyLength1 + copyLength2; } - // TODO: skip and skipn - @Override public byte[] readAllBytes() throws IOException { throw new IOException("Reading all bytes from a BigByteArrayInputStream is prohibited because it might exceed the array capacity"); diff --git a/src/main/java/org/aksw/iguana/commons/io/BigByteArrayOutputStream.java b/src/main/java/org/aksw/iguana/commons/io/BigByteArrayOutputStream.java index 2d299c056..2085b4158 100644 --- a/src/main/java/org/aksw/iguana/commons/io/BigByteArrayOutputStream.java +++ b/src/main/java/org/aksw/iguana/commons/io/BigByteArrayOutputStream.java @@ -83,8 +83,8 @@ public BigByteArrayOutputStream(long bufferSize) { if (bufferSize <= ARRAY_SIZE_LIMIT) { baosList = new ArrayList<>(1); baosList.add(new ByteArrayOutputStream((int) bufferSize)); - } else { // TODO: fix the line below - final var requiredBaoss = (int) (bufferSize / ARRAY_SIZE_LIMIT) + 1; // this might create a fully sized, but empty baos at the end if the buffer size is a multiple of ARRAY_SIZE_LIMIT + } else { + final var requiredBaoss = (int) ((bufferSize - 1) / ARRAY_SIZE_LIMIT) + 1; // -1 to prevent creating a fully sized, but empty baos at the end if the buffer size is a multiple of ARRAY_SIZE_LIMIT baosList = new ArrayList<>(requiredBaoss); IntStream.range(0, requiredBaoss).forEachOrdered(i -> baosList.add(new ByteArrayOutputStream(ARRAY_SIZE_LIMIT))); } diff --git a/src/test/java/org/aksw/iguana/commons/io/BigByteArrayOutputStreamTest.java b/src/test/java/org/aksw/iguana/commons/io/BigByteArrayOutputStreamTest.java index 285d387ab..0863267a1 100644 --- a/src/test/java/org/aksw/iguana/commons/io/BigByteArrayOutputStreamTest.java +++ b/src/test/java/org/aksw/iguana/commons/io/BigByteArrayOutputStreamTest.java @@ -21,16 +21,16 @@ class BigByteArrayOutputStreamTest { final static Random rng = new Random(0); public static List data() { - final var maxSize = Integer.MAX_VALUE - 8; + final long maxSize = Integer.MAX_VALUE - 8; - final Supplier sup1 = () -> getBigRandomBuffer(10, maxSize); - final Supplier sup2 = () -> getBigRandomBuffer((long) maxSize * 2L, maxSize); + final Supplier sup1 = () -> getBigRandomBuffer(10L, (int) maxSize); + final Supplier sup2 = () -> getBigRandomBuffer(maxSize * 2L, (int) maxSize); return List.of( Arguments.of(Named.of(String.valueOf(10), sup1), 10, new int[] { 10 }), - Arguments.of(Named.of(String.valueOf(10), sup1), maxSize * 2L, new int[] { maxSize, maxSize, maxSize }), // small data, high initial capacity - Arguments.of(Named.of(String.valueOf(maxSize * 2L), sup2), maxSize * 2L, new int[] { maxSize, maxSize, maxSize }), - Arguments.of(Named.of(String.valueOf(maxSize * 2L), sup2), 0, new int[] { maxSize, maxSize }) + Arguments.of(Named.of(String.valueOf(10), sup1), maxSize * 2L, new int[] {(int) maxSize, (int) maxSize}), // small data, high initial capacity + Arguments.of(Named.of(String.valueOf(maxSize * 2L), sup2), maxSize * 2L, new int[] {(int) maxSize, (int) maxSize}), + Arguments.of(Named.of(String.valueOf(maxSize * 2L), sup2), 0, new int[] {(int) maxSize, (int) maxSize}) ); }