/** * Method that tries to append data in buffer if there is enough room; * if there is, data is appended and 'true' returned; otherwise no changes * are made and 'false' is returned. */ public abstract boolean tryAppend(byte[] data, int dataOffset, int dataLength);
/** * Method that tries to append data in buffer if there is enough room; * if there is, data is appended and 'true' returned; otherwise no changes * are made and 'false' is returned. */ public abstract boolean tryAppend(byte[] data, int dataOffset, int dataLength);
/** * Method that tries to append value in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void append(byte value) { if (!tryAppend(value)) { throw new IllegalStateException("Not enough room in buffer to append a single value (can't allocate enough new segments)"); } }
/** * Method that tries to append data in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void append(byte[] data, int dataOffset, int dataLength) { if (!tryAppend(data, dataOffset, dataLength)) { throw new IllegalStateException("Not enough room in buffer to append entry of "+dataLength +" (can't allocate enough new segments)"); } }
/** * Method that tries to append data in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void append(byte[] data, int dataOffset, int dataLength) { if (!tryAppend(data, dataOffset, dataLength)) { throw new IllegalStateException("Not enough room in buffer to append entry of "+dataLength +" (can't allocate enough new segments)"); } }
/** * Method that tries to append value in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void append(byte value) { if (!tryAppend(value)) { throw new IllegalStateException("Not enough room in buffer to append a single value (can't allocate enough new segments)"); } }
@Override public void write(final byte[] data, final int off, final int len) throws IOException { if (!inputBuffer.tryAppend(data, off, len)) { // Buffer full - need to flush // TODO sync with HTTP call, performance hit? flushUnderlyingBufferAndReset(); if (!inputBuffer.tryAppend(data, off, len)) { log.warn("Unable to append data: 1 byte lost"); } } }
if (!offHeap.tryAppend(readBuffer, 0, count)) {
if ((offHeap == null) || !offHeap.tryAppend(readBuffer, 0, count)) { _verifyBufferLength(offHeap, total);
} else { if (offHeap != null) { if (!offHeap.tryAppend(readBuffer, 0, incomingReadByteCount)) { throw new IOException("Internal problem: failed to append "+incomingReadByteCount+" in an off-heap buffer");