private static byte[] readBytes(RandomAccessFile target, int count) throws IOException {
        final byte[] bytes = new byte[count];
        int total = 0;
        int len;

        while (0 < (len = target.read(bytes, total, count - total))) {
            total += len;
        }
        if (total < count) {
            throw new IOException();
        }
        return bytes;
    }