class ResumableRandomAccessFileListener implements ResumableListener {
    private final RandomAccessFile file;

    public ResumableRandomAccessFileListener(RandomAccessFile file) {
        this.file = file;
    }

    /**
     * This method uses the last valid bytes written on disk to position a {@link RandomAccessFile}, allowing
     * resumable file download.
     *
     * @param buffer a {@link ByteBuffer}
     * @throws IOException exception while writing into the file
     */
    @Override
    public void onBytesReceived(ByteBuffer buffer) throws IOException {
        file.seek(file.length());
        if (buffer.hasArray()) {
            file.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
        } else { // if the buffer is direct or backed by a String...
            byte[] b = new byte[buffer.remaining()];
            int pos = buffer.position();
            buffer.get(b);
            buffer.position(pos);
            file.write(b);
        }
    }

    @Override
    public void onAllBytesReceived() {
        closeSilently(file);
    }

    @Override
    public long length() {<FILL_FUNCTION_BODY>}
}

        try {
            return file.length();
        } catch (IOException e) {
            return -1;
        }
    
<no_super_class>