/** * Return a {@link ByteBuffersDataInput} for the set of current buffers ({@link #toBufferList()}). */ public ByteBuffersDataInput toDataInput() { return new ByteBuffersDataInput(toBufferList()); }
/** * Copy the current content of this object into another {@link DataOutput}. */ public void copyTo(DataOutput output) throws IOException { for (ByteBuffer bb : toBufferList()) { if (bb.hasArray()) { output.writeBytes(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining()); } else { output.copyBytes(new ByteBuffersDataInput(Arrays.asList(bb)), bb.remaining()); } } }
/** * Return a contiguous array with the current content written to the output. The returned * array is always a copy (can be mutated). */ public byte[] toArrayCopy() { if (blocks.size() == 0) { return EMPTY_BYTE_ARRAY; } // We could try to detect single-block, array-based ByteBuffer here // and use Arrays.copyOfRange, but I don't think it's worth the extra // instance checks. byte [] arr = new byte[Math.toIntExact(size())]; int offset = 0; for (ByteBuffer bb : toBufferList()) { int len = bb.remaining(); bb.get(arr, offset, len); offset += len; } return arr; }
checksum.reset(); byte [] buffer = null; for (ByteBuffer bb : delegate.toBufferList()) { if (bb.hasArray()) { checksum.update(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());
/** * Return a {@link ByteBuffersDataInput} for the set of current buffers ({@link #toBufferList()}). */ public ByteBuffersDataInput toDataInput() { return new ByteBuffersDataInput(toBufferList()); }
/** * Return a contiguous array with the current content written to the output. The returned * array is always a copy (can be mutated). */ public byte[] toArrayCopy() { if (blocks.size() == 0) { return EMPTY_BYTE_ARRAY; } // We could try to detect single-block, array-based ByteBuffer here // and use Arrays.copyOfRange, but I don't think it's worth the extra // instance checks. byte [] arr = new byte[Math.toIntExact(size())]; int offset = 0; for (ByteBuffer bb : toBufferList()) { int len = bb.remaining(); bb.get(arr, offset, len); offset += len; } return arr; }
/** * Copy the current content of this object into another {@link DataOutput}. */ public void copyTo(DataOutput output) throws IOException { for (ByteBuffer bb : toBufferList()) { if (bb.hasArray()) { output.writeBytes(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining()); } else { output.copyBytes(new ByteBuffersDataInput(Arrays.asList(bb)), bb.remaining()); } } }
checksum.reset(); byte [] buffer = null; for (ByteBuffer bb : delegate.toBufferList()) { if (bb.hasArray()) { checksum.update(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining());