@Test(expected = EOFException.class) public void readTooMuch() throws Exception { byte expected[] = setupWithCrc((byte) 0, true, 0, 4); byte output[] = new byte[expected.length + 1024]; try (FileChannel fd = FileChannel.open(file, StandardOpenOption.READ)) { try (FileReader reader = new Crc32VerifyingFileReader(new FileChannelReader(fd, 0), expected.length, 4)) { int i = 0; while (i < output.length) i += reader.read(ByteBuffer.wrap(output, i, Integer.min(output.length - i, 128))); } } }
@Override public int read(ByteBuffer data) throws IOException { return forRead.read(data); }
Crc32VerifyingFileReader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { return forRead.read(data); } }
Crc32VerifyingFileReader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { return forRead.read(data); } Crc32VerifyingFileReader(@NonNull FileReader in, long len, int roundUp); }
Crc32VerifyingFileReader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { return forRead.read(data); } Crc32VerifyingFileReader(@NonNull FileReader in, long len, int roundUp); @Override int read(ByteBuffer data); @Override void close(); @Override ByteBuffer allocateByteBuffer(int size); }
Crc32VerifyingFileReader implements FileReader { @Override public int read(ByteBuffer data) throws IOException { return forRead.read(data); } Crc32VerifyingFileReader(@NonNull FileReader in, long len, int roundUp); @Override int read(ByteBuffer data); @Override void close(); @Override ByteBuffer allocateByteBuffer(int size); static final int CRC_LEN; }