private void saveByte(int inputByte) throws IOException {
        if (byteBuffer != null) {
            if (bufferPointer == maxBytesInMemory) {
                // Need to switch to file
                storeFile = Files.createTempFile("TIKA_streamstore_", ".tmp").toFile();
                storeOutputStream = new BufferedOutputStream(new FileOutputStream(storeFile));
                // Save what we have so far in buffer
                storeOutputStream.write(byteBuffer, 0, bufferPointer);
                // Write the new byte
                storeOutputStream.write(inputByte);
                byteBuffer = null; // release for garbage collection
            } else {
                // Continue writing to buffer
                byteBuffer[bufferPointer++] = (byte) inputByte;
            }
        } else {
            storeOutputStream.write(inputByte);
        }
    }
Saves the bytes read from the original stream to buffer or file
tika-core/src/main/java/org/apache/tika/utils/RereadableInputStream.java