public static byte[] readChunk(RandomAccessFile file, long startPosition, int size) throws IOException {
        byte tmp = -1;
        byte[] chunk = new byte[size];
        int index = 0;
        file.seek(startPosition);
        
        try {
            while (index < size && (tmp = file.readByte()) != -1) {
                chunk[index++] = tmp;
            }
        } catch (EOFException e) {
        }
        return chunk;
    }