/** * Read data from a set of contiguous buffers. All data buffers except for the last one * must have an identical remaining number of bytes in the buffer (that is a power of two). The last * buffer can be of an arbitrary remaining length. */ public ByteBuffersDataInput(List<ByteBuffer> buffers) { ensureAssumptions(buffers); this.blocks = buffers.stream().map(buf -> buf.asReadOnlyBuffer()).toArray(ByteBuffer[]::new); if (blocks.length == 1) { this.blockBits = 32; this.blockMask = ~0; } else { final int blockBytes = determineBlockPage(buffers); this.blockBits = Integer.numberOfTrailingZeros(blockBytes); this.blockMask = (1 << blockBits) - 1; } this.size = Arrays.stream(blocks).mapToLong(block -> block.remaining()).sum(); // The initial "position" of this stream is shifted by the position of the first block. this.offset = blocks[0].position(); this.pos = offset; }
private static List<ByteBuffer> sliceBufferList(List<ByteBuffer> buffers, long offset, long length) { ensureAssumptions(buffers);
/** * Read data from a set of contiguous buffers. All data buffers except for the last one * must have an identical remaining number of bytes in the buffer (that is a power of two). The last * buffer can be of an arbitrary remaining length. */ public ByteBuffersDataInput(List<ByteBuffer> buffers) { ensureAssumptions(buffers); this.blocks = buffers.stream().map(buf -> buf.asReadOnlyBuffer()).toArray(ByteBuffer[]::new); if (blocks.length == 1) { this.blockBits = 32; this.blockMask = ~0; } else { final int blockBytes = determineBlockPage(buffers); this.blockBits = Integer.numberOfTrailingZeros(blockBytes); this.blockMask = (1 << blockBits) - 1; } this.size = Arrays.stream(blocks).mapToLong(block -> block.remaining()).sum(); // The initial "position" of this stream is shifted by the position of the first block. this.offset = blocks[0].position(); this.pos = offset; }
private static List<ByteBuffer> sliceBufferList(List<ByteBuffer> buffers, long offset, long length) { ensureAssumptions(buffers);