private void fillBuffer() throws IOException {

        //
        // Move a partial record to the beginning of the stream buffer
        //
        if (residualLength != 0 && next != 0)
            System.arraycopy(stream, next, stream, 0, residualLength);

        next = 0;

        //
        // Fill the buffer unless we are at the end of the file
        //
        if (!endOfData) {
            int offset = next + residualLength;

            if (offset < size) {
                int length = read(stream, offset, size-offset);
                if (length > 0)
                    residualLength += length;
                else
                    endOfData = true;
            }
        }
    }