@Override protected int get(DataInfo item, byte[] buffer, int offset, int length) { return item.readInto(buffer, offset, length); }
/** * <p>Reads and consumes the content bytes of this {@link DataInfo} into the given {@link ByteBuffer}.</p> * * @param output the {@link ByteBuffer} to copy the bytes into * @return the number of bytes copied * @see #consume(int) */ public int consumeInto(ByteBuffer output) { int read = readInto(output); consume(read); return read; }
/** * <p>Reads and consumes the content bytes of this {@link DataInfo} into the given byte array, * starting from index {@code offset} for {@code length} bytes.</p> * * @param bytes the byte array to copy the bytes into * @param offset the offset of the byte array to start copying * @param length the number of bytes to copy * @return the number of bytes copied */ public int consumeInto(byte[] bytes, int offset, int length) { int read = readInto(bytes, offset, length); consume(read); return read; }
/** * @return a {@link ByteBuffer} with the content of this {@link DataInfo} * @param consume whether to consume the content */ public ByteBuffer asByteBuffer(boolean consume) { ByteBuffer buffer = allocate(available()); if (consume) consumeInto(buffer); else readInto(buffer); buffer.flip(); return buffer; }