public ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer) { this(allocate(capacity, useDirectByteBuffer)); }
protected void checkSizeAndGrow(int extra) { long capacityNeeded = curBuf.position() + (long) extra; if (capacityNeeded > curBuf.limit()) { // guarantee it's possible to fit if (capacityNeeded > MAX_ARRAY_SIZE) { throw new BufferOverflowException(); } // double until hit the cap long nextCapacity = Math.min(curBuf.capacity() * 2L, MAX_ARRAY_SIZE); // but make sure there is enough if twice the existing capacity is still too small nextCapacity = Math.max(nextCapacity, capacityNeeded); ByteBuffer newBuf = allocate((int) nextCapacity, curBuf.isDirect()); curBuf.flip(); ByteBufferUtils.copyFromBufferToBuffer(curBuf, newBuf); curBuf = newBuf; } }
public ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer) { this(allocate(capacity, useDirectByteBuffer)); }
public ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer) { this(allocate(capacity, useDirectByteBuffer)); }
public ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer) { this(allocate(capacity, useDirectByteBuffer)); }
private void checkSizeAndGrow(int extra) { long capacityNeeded = buf.position() + (long) extra; if (capacityNeeded > buf.limit()) { // guarantee it's possible to fit if (capacityNeeded > MAX_ARRAY_SIZE) { throw new BufferOverflowException(); } // double until hit the cap long nextCapacity = Math.min(buf.capacity() * 2L, MAX_ARRAY_SIZE); // but make sure there is enough if twice the existing capacity is still too small nextCapacity = Math.max(nextCapacity, capacityNeeded); ByteBuffer newBuf = allocate((int) nextCapacity, buf.isDirect()); buf.flip(); newBuf.put(buf); buf = newBuf; } }
protected void checkSizeAndGrow(int extra) { long capacityNeeded = curBuf.position() + (long) extra; if (capacityNeeded > curBuf.limit()) { // guarantee it's possible to fit if (capacityNeeded > MAX_ARRAY_SIZE) { throw new BufferOverflowException(); } // double until hit the cap long nextCapacity = Math.min(curBuf.capacity() * 2L, MAX_ARRAY_SIZE); // but make sure there is enough if twice the existing capacity is still too small nextCapacity = Math.max(nextCapacity, capacityNeeded); ByteBuffer newBuf = allocate((int) nextCapacity, curBuf.isDirect()); curBuf.flip(); ByteBufferUtils.copyFromBufferToBuffer(curBuf, newBuf); curBuf = newBuf; } }
protected void checkSizeAndGrow(int extra) { long capacityNeeded = curBuf.position() + (long) extra; if (capacityNeeded > curBuf.limit()) { // guarantee it's possible to fit if (capacityNeeded > MAX_ARRAY_SIZE) { throw new BufferOverflowException(); } // double until hit the cap long nextCapacity = Math.min(curBuf.capacity() * 2L, MAX_ARRAY_SIZE); // but make sure there is enough if twice the existing capacity is still too small nextCapacity = Math.max(nextCapacity, capacityNeeded); ByteBuffer newBuf = allocate((int) nextCapacity, curBuf.isDirect()); curBuf.flip(); ByteBufferUtils.copyFromBufferToBuffer(curBuf, newBuf); curBuf = newBuf; } }