@Test public void read() throws Exception { byte output[] = new byte[data.length]; int outputCrc; try (FileChannel fd = FileChannel.open(file, StandardOpenOption.READ)) { try (Crc32Reader reader = new Crc32Reader(new FileChannelReader(fd, 0))) { int i = 0; while (i < output.length) i += reader.read(ByteBuffer.wrap(output, i, Integer.min(output.length - i, 128))); outputCrc = reader.getCrc32(); } } assertEquals(expectedCrc32, outputCrc); assertArrayEquals(data, output); }
@Override public int read(ByteBuffer data) throws IOException { final ByteBuffer copy = data.asReadOnlyBuffer(); final int rlen = in.read(data); read += rlen; copy.limit(copy.position() + rlen); crc32.update(copy); return rlen; }
Crc32Reader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { final ByteBuffer copy = data.asReadOnlyBuffer(); final int rlen = in.read(data); read += rlen; copy.limit(copy.position() + rlen); crc32.update(copy); return rlen; } }
Crc32Reader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { final ByteBuffer copy = data.asReadOnlyBuffer(); final int rlen = in.read(data); read += rlen; copy.limit(copy.position() + rlen); crc32.update(copy); return rlen; }  }
Crc32Reader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { final ByteBuffer copy = data.asReadOnlyBuffer(); final int rlen = in.read(data); read += rlen; copy.limit(copy.position() + rlen); crc32.update(copy); return rlen; }  int getCrc32(); @Override int read(ByteBuffer data); @Override void close(); @Override ByteBuffer allocateByteBuffer(int size); }
Crc32Reader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { final ByteBuffer copy = data.asReadOnlyBuffer(); final int rlen = in.read(data); read += rlen; copy.limit(copy.position() + rlen); crc32.update(copy); return rlen; }  int getCrc32(); @Override int read(ByteBuffer data); @Override void close(); @Override ByteBuffer allocateByteBuffer(int size); static final int CRC_LEN; }