public int fillBuffer()

in core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java [105:137]


    public int fillBuffer() throws IOException {
        if (tempBuffer) {
            // we was on tempBuffer.
            // check that we completed the tempBuffer
            if (bufpos != buflen) throw new IllegalStateException("unread only works when a buffer is fully read before the next refill is asked!");
            // restore the original buffer
            buffer = origBuffer;
            buflen = origBuflen;
            bufpos = origBufpos;
            tempBuffer = false;
            // return that we just read bufferLen data.
            return bufferLen();
        }
        // compact the buffer if necessary
        if (this.bufpos > 0) { // could swtich to (this.buffer.length / 2) but needs a 4*boundary capacity, then (instead of 2).
            int len = bufferLen();
            if (len > 0) {
                System.arraycopy(this.buffer, this.bufpos, this.buffer, 0, len);
            }
            this.bufpos = 0;
            this.buflen = len;
        }
        int l;
        int off = this.buflen;
        int len = this.buffer.length - off;
        l = in.read(this.buffer, off, len);
        if (l == -1) {
            return -1;
        } else {
            this.buflen = off + l;
            return l;
        }
    }