private static int readFile(@NonNull final FileChannel channel, final long startPos, final int length, @NonNull final byte[] buffer, final int bufferOffset) throws IOException {
        if (bufferOffset + length > buffer.length) {
            throw new IllegalArgumentException("Requested read length " + length + " will not fit in given buffer length " + buffer.length + " (offset: " + bufferOffset + ")");
        }

        final ByteBuffer bb = ByteBuffer.wrap(buffer, bufferOffset, length);
        return channel.read(bb, startPos);
    }
Reads bytes from a file

@param startPos position to read from in the file
@param length   number of bytes to read
@param buffer   buffer to store read bytes in
@throws IOException in case anything goes wrong
main/src/main/java/cgeo/geocaching/storage/FileByteReader.java