@Test(expectedExceptions = EOFException.class) public void testReadFullyThrowWhenItCantReadEnough() throws IOException { try(final SeekableByteChannel channel = Files.newByteChannel(DEFECTIVE.toPath())){ final ByteBuffer readBuffer = ByteBuffer.allocate(1000); Assert.assertTrue(channel.size() < readBuffer.capacity()); BlockCompressedInputStream.readFully(channel, readBuffer); } }
readFully(channel, lastBlockBuffer); if (Arrays.equals(lastBlockBuffer.array(), BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK)) { return FileTermination.HAS_TERMINATOR_BLOCK; final byte[] bufferArray = new byte[bufsize]; channel.position(fileSize - bufsize); readFully(channel, ByteBuffer.wrap(bufferArray)); for (int i = bufferArray.length - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length; i >= 0; --i) {
readFully(channel, lastBlockBuffer); if (Arrays.equals(lastBlockBuffer.array(), BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK)) { return FileTermination.HAS_TERMINATOR_BLOCK; final byte[] bufferArray = new byte[bufsize]; channel.position(fileSize - bufsize); readFully(channel, ByteBuffer.wrap(bufferArray)); for (int i = bufferArray.length - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length; i >= 0; --i) {
readFully(channel, lastBlockBuffer); if (Arrays.equals(lastBlockBuffer.array(), BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK)) { return FileTermination.HAS_TERMINATOR_BLOCK; final byte[] bufferArray = new byte[bufsize]; channel.position(fileSize - bufsize); readFully(channel, ByteBuffer.wrap(bufferArray)); for (int i = bufferArray.length - BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK.length; i >= 0; --i) {
@Test public void testReadFullyReadsBytesCorrectly() throws IOException { try(final SeekableByteChannel channel = Files.newByteChannel(DEFECTIVE.toPath())){ final ByteBuffer readBuffer = ByteBuffer.allocate(10); Assert.assertTrue(channel.size() > readBuffer.capacity()); BlockCompressedInputStream.readFully(channel, readBuffer); ByteBuffer expected = ByteBuffer.allocate(10); channel.position(0).read(expected); Assert.assertEquals(readBuffer.array(), expected.array()); } }