Package java.io

Examples of java.io.InputStream.mark()


    byte[] big = newPreFilledByteArray(5);
    InputStream bin = new ByteArrayInputStream(big);
    InputStream lin = ByteStreams.limit(bin, 2);

    // also test available
    lin.mark(2);
    assertEquals(2, lin.available());
    lin.skip(1);
    assertEquals(1, lin.available());

    lin.reset();
View Full Code Here


     * @throws IOException if something goes wrong
     */
    public void testMarkResetSimplePosZero()
            throws IOException {
        InputStream is = getStream(100);
        is.mark(10);
        assertEquals(10, is.read(new byte[10]));
        is.reset();
        checkBeginningOfStream(is);
    }

View Full Code Here

     */
    public void testMarkResetSimplePosNonZero()
            throws IOException {
        InputStream is = getStream(200);
        assertEquals(127, is.read(new byte[127]));
        is.mark(10);
        byte[] readBeforeReset = new byte[10];
        byte[] readAfterReset = new byte[10];
        assertEquals(10, is.read(readBeforeReset));
        is.reset();
        assertEquals(10, is.read(readAfterReset));
View Full Code Here

        InputStream is = getStream(128*1024);
        byte[] buf = new byte[DEFAULT_INTERNAL_BUFFER_SIZE - 2*1024];
        fillArray(is, buf);
        // The following mark fits within the existing default buffer, but the
        // bytes after the mark have to be shifted to the left.
        is.mark(4*1024);
        byte[] readBeforeReset = new byte[3*1024];
        byte[] readAfterReset = new byte[3*1024];
        fillArray(is, readBeforeReset);
        // Obtain something to compare with.
        InputStream src = getStream(128*1024);
 
View Full Code Here

        InputStream is = getStream(128*1024);
        is.read();
        is.read();
        // The following mark fits within the existing default buffer, but the
        // bytes after the mark have to be shifted to the left.
        is.mark(DEFAULT_INTERNAL_BUFFER_SIZE -6);
        byte[] readBeforeReset = new byte[DEFAULT_INTERNAL_BUFFER_SIZE -6];
        byte[] readAfterReset = new byte[DEFAULT_INTERNAL_BUFFER_SIZE -6];
        fillArray(is, readBeforeReset);
        // Obtain something to compare with.
        InputStream src = getStream(128*1024);
 
View Full Code Here

     * @throws IOException if something goes wrong
     */
    public void testMarkResetExceedReadAheadLimitOK_Internal()
            throws IOException {
        InputStream is = getStream(4*1024+17);
        is.mark(10);
        assertEquals(20, is.read(new byte[20]));
        // Note the following is implementation dependent.
        // Since the bytes are already stored in the internal buffer, we won't
        // fail the reset even though we have exceeded the read ahead limit.
        // With a different stream implementation, this may fail!
View Full Code Here

     * @throws IOException if something goes wrong
     */
    public void testMarkResetExceedReadAheadLimitFail_Internal()
            throws IOException {
        InputStream is = getStream(64*1024+17);
        is.mark(10);
        // The internal buffer is 32 KB (implementation detail).
        int toRead = 38*1024+7;
        int read = 0;
        byte[] buf = new byte[toRead];
        while (read < toRead) {
View Full Code Here

     * @throws IOException if something goes wrong
     */
    public void testMarkResetOverflowInternalBufferKeepBytes()
            throws IOException {
        InputStream is = getStream(128*1024);
        is.mark(120*1024);
        byte[] buf = new byte[120*1024-1];
        fillArray(is, buf);
        is.reset();
        checkBeginningOfStream(is);

View Full Code Here

        is.reset();
        checkBeginningOfStream(is);

        // Again, but this time read past the read ahead limit.
        is = getStream(36*1024);
        is.mark(4*1024);
        buf = new byte[36*1024-1];
        fillArray(is, buf);
        try {
            is.reset();
            fail("reset-call was expected to throw IOException");
View Full Code Here

     */
    public void testMarkReadUntilEOF()
            throws IOException {
        // Try with a single buffer fill first.
        InputStream is = getStream(4*1024);
        is.mark(8*1024);
        byte[] buf = new byte[8*1024];
        int read = 0;
        while (true) {
            int readNow = is.read(buf, read, buf.length - read);
            if (readNow == -1) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.