@Override public int read(byte[] buffer, int offset, int length) { int count = _buffer.readIfAvailable(buffer, offset, length); // need to translate 0 to -1, to signify end-of-content return (count <= 0) ? -1 : count; }
@Override public int available() { long l = _buffer.available(); if (l > Integer.MAX_VALUE) { return Integer.MAX_VALUE; } return (int) l; }
/** * Method that tries to append an entry in buffer if there is enough room; * if there is, entry is appended and 'true' returned; otherwise no changes * are made and 'false' is returned. */ public abstract boolean tryAppendEntry(long[] 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);
public MemBuffersForBytes withStreamyDecorator(MemBufferDecorator<StreamyBytesMemBuffer> streamyDecorator) { return new MemBuffersForBytes(_segmentAllocator, _chunkyDecorator, streamyDecorator); }
public long getBytesInMemory() { return inputBuffer.getTotalPayloadLength(); }
/** * Internal method that tries to allocate an off-heap buffer. */ protected StreamyBytesMemBuffer allocOffHeapBuffer() { return _offHeapBuffers.createStreamyBuffer(2, _maxSegmentsPerBuffer); }
/** * Method that tries to append an entry in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void appendEntry(long[] data) { appendEntry(data, 0, data.length); }
/** * Method that tries to append data in buffer if there is enough room; * if there is, data appended and 'true' returned; otherwise no changes * are made and 'false' is returned. */ public abstract boolean tryAppend(long[] data, int dataOffset, int dataLength);
/** * 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) { append(data, 0, data.length); }
/** * Method that tries to append data in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void append(long[] data) { append(data, 0, data.length); }
@Override public long skip(long n) { if (n <= 0L) { return n; } int max = (n < Integer.MAX_VALUE) ? (int) n : Integer.MAX_VALUE; return _buffer.skip(max); } }
public boolean isEmpty() { return inputBuffer.isEmpty(); } }
public long getInMemoryAvailableSpace() { return inputBuffer.getMaximumAvailableSpace(); }
/** * 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 an entry in buffer if there is enough room; * if there is, entry is appended and 'true' returned; otherwise no changes * are made and 'false' is returned. */ public abstract boolean tryAppendEntry(long[] data, int dataOffset, int dataLength);
/** * Method that tries to append an entry in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void appendEntry(long[] data) { appendEntry(data, 0, data.length); }
/** * Method that tries to append data in buffer if there is enough room; * if there is, data appended and 'true' returned; otherwise no changes * are made and 'false' is returned. */ public abstract boolean tryAppend(long[] data, int dataOffset, int dataLength);
/** * 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) { append(data, 0, data.length); }
/** * Method that tries to append data in buffer and returning; * if there is no room, a {@link IllegalStateException} is thrown. */ public final void append(long[] data) { append(data, 0, data.length); }