private void fillBuffer()

in src/main/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressor.java [181:226]


        private void fillBuffer(int byteOffset) throws IOException
        {
            bufferBase = byteOffset;
            synchronized (stream)
            {
                try
                {
                    stream.seek(byteOffset);
                    bufferTop = stream.read(buffer);
                }
                catch (EOFException e)
                {
                    // you never know which kind of EOF will kick in
                    bufferTop = -1;
                }
                // check filling degree
                if (bufferTop > -1 && bufferTop < 3)
                {
                    // CK: if filling degree is too small,
                    // smoothly fill up to the next three bytes or substitute with with
                    // empty bytes
                    int read = 0;
                    while (bufferTop < 3)
                    {
                        try
                        {
                            read = stream.read();
                        }
                        catch (EOFException e)
                        {
                            read = -1;
                        }
                        buffer[bufferTop++] = read == -1 ? 0 : (byte) (read & 0xff);
                    }
                }
            }
            // leave some room, in order to save a few tests in the calling code
            bufferTop -= 3;

            if (bufferTop < 0)
            {
                // if we're at EOF, just supply zero-bytes
                Arrays.fill(buffer, (byte) 0);
                bufferTop = buffer.length - 3;
            }
        }