Skip to content

Commit 0ff877e

Browse files
committed
Change MultiBuffer CHUNK_SIZE to half of max int
1 parent aafbae6 commit 0ff877e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/main/java/com/maxmind/db/BufferHolder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ final class BufferHolder {
5252
if (null == stream) {
5353
throw new NullPointerException("Unable to use a NULL InputStream");
5454
}
55-
final int chunkSize = Integer.MAX_VALUE;
55+
final int chunkSize = Integer.MAX_VALUE / 2;
5656
List<ByteBuffer> chunks = new ArrayList<>();
5757
long total = 0;
5858
byte[] tmp = new byte[chunkSize];
5959
int read;
6060

6161
while (-1 != (read = stream.read(tmp))) {
62-
ByteBuffer chunk = ByteBuffer.allocateDirect(read);
62+
ByteBuffer chunk = ByteBuffer.allocate(read);
6363
chunk.put(tmp, 0, read);
6464
chunk.flip();
6565
chunks.add(chunk);
6666
total += read;
6767
}
6868

69-
if (total <= Integer.MAX_VALUE) {
69+
if (total <= chunkSize) {
7070
byte[] data = new byte[(int) total];
7171
int pos = 0;
7272
for (ByteBuffer chunk : chunks) {

src/main/java/com/maxmind/db/MultiBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class MultiBuffer implements Buffer {
2424

2525
/** Maximum size per underlying chunk. */
26-
static final int CHUNK_SIZE = Integer.MAX_VALUE;
26+
static final int CHUNK_SIZE = Integer.MAX_VALUE / 2;
2727

2828
final List<ByteBuffer> buffers = new ArrayList<>();
2929
private final long capacity;

0 commit comments

Comments
 (0)