@Override
    public synchronized int read() throws IOException {
        // Use local refs since buf and in may be invalidated by an
        // unsynchronized close()
        byte[] localBuf = buf;
        InputStream localIn = in;
        if (localBuf == null || localIn == null) {
            throw streamClosed();
        }

        // Are there buffered bytes available?
        if (pos >= count && fillbuf(localIn, localBuf) == -1) {
            // no, fill buffer
            return -1;
        }
        // localBuf may have been invalidated by fillbuf
        if (localBuf != buf) {
            localBuf = buf;
            if (localBuf == null) {
                throw streamClosed();
            }
        }

        // Did filling the buffer fail with -1 (EOF)?
        if (count - pos > 0) {
            return localBuf[pos++] & 0xFF;
        }
        return -1;
    }
Reads a single byte from this stream and returns it as an integer in the
range from 0 to 255. Returns -1 if the end of the source string has been
reached. If the internal buffer does not contain any available bytes then
it is filled from the source stream and the first byte is returned.

@return the byte read or -1 if the end of the source stream has been
        reached.
@throws IOException
            if this stream is closed or another IOException occurs.
core/src/main/java/com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream.java