private void readEntireStream(int testSize) throws IOException {
        InputStream is = createTestInputStream(testSize);
        try (RereadableInputStream ris = new RereadableInputStream(is, MEMORY_THRESHOLD, true)) {
            for (int pass = 0; pass < NUM_PASSES; pass++) {
                for (int byteNum = 0; byteNum < testSize; byteNum++) {
                    int byteRead = ris.read();
                    assertEquals(byteNum, byteRead,
                            "Pass = " + pass + ", byte num should be " + byteNum + " but is " +
                                    byteRead + ".");
                }
                int eof = ris.read();
                assertEquals(-1, eof,
                        "Pass = " + pass + ", byte num should be " + -1 + " but is " + eof + ".");
                ris.rewind();
            }
        }
    }
Read entire stream of various sizes
tika-core/src/test/java/org/apache/tika/TestRereadableInputStream.java