public int read() throws IOException {
        if (closed) {
            throw new IOException("Stream is already closed");
        }

        int inputByte = inputStream.read();
        if (inputByte == -1 && inputStream != originalInputStream) {
            // If we got EOF reading from buffer or file, switch to the original stream and get
            // the next byte from there instead
            if (readingFromBuffer) {
                readingFromBuffer = false;
                inputStream.close();  // Close the input byte stream
            } else {
                inputStream.close();  // Close the input file stream
                // start appending to the file
                storeOutputStream = new BufferedOutputStream(new FileOutputStream(storeFile, true));
            }
            // The original stream is now the current stream
            inputStream = originalInputStream;
            inputByte = inputStream.read();
        }

        if (inputByte != -1 && inputStream == originalInputStream) {
            // If not EOF and reading from original stream, save the bytes we read
            saveByte(inputByte);
        }

        return inputByte;
    }
Reads a byte from the stream, saving it in the store if it is being
read from the original stream.  Implements the abstract
InputStream.read().

@return the read byte, or -1 on end of stream.
@throws IOException
tika-core/src/main/java/org/apache/tika/utils/RereadableInputStream.java