@Override
    public void seek(long desired) throws IOException {
        final int available = compressingDelegate.available();
        if (available > 0) {
            if (available != compressingDelegate.skip(available)) {
                throw new IOException("Unable to skip buffered data.");
            }
        }
        delegate.seek(desired);
    }
@Test
    void testSeek() throws IOException {
        final List<String> records = Arrays.asList("first", "second", "third", "fourth", "fifth");
        final Map<String, Long> positions = new HashMap<>();

        byte[] compressedBytes;
        try (final TestingOutputStream outputStream = new TestingOutputStream();
                final CompressibleFSDataOutputStream compressibleOutputStream =
                        new CompressibleFSDataOutputStream(
                                outputStream, new SnappyStreamCompressionDecorator())) {
            for (String record : records) {
                positions.put(record, compressibleOutputStream.getPos());
                compressibleOutputStream.write(record.getBytes(StandardCharsets.UTF_8));
            }
            compressibleOutputStream.flush();
            compressedBytes = outputStream.toByteArray();
        }

        try (final FSDataInputStream inputStream =
                        new InputStreamFSInputWrapper(new ByteArrayInputStream(compressedBytes));
                final FSDataInputStream compressibleInputStream =
                        new CompressibleFSDataInputStream(
                                inputStream, new SnappyStreamCompressionDecorator())) {
            verifyRecord(compressibleInputStream, positions, "first");
            verifyRecord(compressibleInputStream, positions, "third");
            verifyRecord(compressibleInputStream, positions, "fifth");
        }

        // Verify read of partial records. This ensures that we skip any unread data in the
        // underlying buffers.
        try (final FSDataInputStream inputStream =
                        new InputStreamFSInputWrapper(new ByteArrayInputStream(compressedBytes));
                final FSDataInputStream compressibleInputStream =
                        new CompressibleFSDataInputStream(
                                inputStream, new SnappyStreamCompressionDecorator())) {
            verifyRecordPrefix(compressibleInputStream, positions, "first", "fir");
            verifyRecordPrefix(compressibleInputStream, positions, "third", "thi");
            verifyRecord(compressibleInputStream, positions, "fifth");
        }
    }