@Test
    public void testMarkAndResetWithWrongExpectedLength() throws Exception {
        InputStream in = new ByteArrayInputStream(sampleData.getBytes());
        LengthCheckInputStream rvis = new LengthCheckInputStream(in,
                sampleData.getBytes().length + 1, INCLUDE_SKIPPED_BYTES);

        rvis.read(new byte[100]);
        rvis.mark(100);
        rvis.read(new byte[100]);
        rvis.reset();
        rvis.read(new byte[sampleData.getBytes().length - 100]);
        try {
            rvis.read();
            fail();
        } catch (Exception e) {
            System.out
                    .println("Exception occurred. Message: " + e.getMessage());
        }

        rvis.close();

    }
This test case initiates a mark after reading 100 bytes from the stream.
Reads the next 100 bytes from the stream. Now the stream is reset and it
is drained. At the last read, the length validation must fail because the
stream was initialized with wrong expected length.
aws-java-sdk-core/src/test/java/com/amazonaws/util/LengthCheckInputStreamTest.java