public byte[] getBlock(int blockStart, int blockLength) throws IOException
    {
        // We include a separate check for int overflow.
        if ((blockStart < 0)
                || (blockLength < 0)
                || (blockStart + blockLength < 0)
                || (blockStart + blockLength > streamLength.longValue())) {
            throw new IOException("Could not read block (block start: " + blockStart
                    + ", block length: " + blockLength + ", data length: "
                    + streamLength + ").");
        }

        InputStream is = getInputStream();
        is.skip(blockStart);

        byte bytes[] = new byte[blockLength];
        int total = 0;
        while (true)
        {
            int read = is.read(bytes, total, bytes.length - total);
            if (read < 1)
                throw new IOException("Could not read block.");
            total += read;
            if (total >= blockLength)
                return bytes;
        }
    }