Package java.io

Examples of java.io.BufferedInputStream.mark()


        in.reset();
        assertTrue("Wrong bytes", in.read() == 6 && in.read() == 7);

        in = new BufferedInputStream(new ByteArrayInputStream(bytes), 12);
        in.skip(6);
        in.mark(8);
        in.skip(7);
        in.reset();
        assertTrue("Wrong bytes 2", in.read() == 6 && in.read() == 7);

        BufferedInputStream buf = new BufferedInputStream(
View Full Code Here


        in.reset();
        assertTrue("Wrong bytes 2", in.read() == 6 && in.read() == 7);

        BufferedInputStream buf = new BufferedInputStream(
                new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 }), 2);
        buf.mark(3);
        bytes = new byte[3];
        int result = buf.read(bytes);
        assertEquals(3, result);
        assertEquals("Assert 0:", 0, bytes[0]);
        assertEquals("Assert 1:", 1, bytes[1]);
View Full Code Here

        assertEquals("Assert 2:", 2, bytes[2]);
        assertEquals("Assert 3:", 3, buf.read());

        buf = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 0,
                1, 2, 3, 4 }), 2);
        buf.mark(3);
        bytes = new byte[4];
        result = buf.read(bytes);
        assertEquals(4, result);
        assertEquals("Assert 4:", 0, bytes[0]);
        assertEquals("Assert 5:", 1, bytes[1]);
View Full Code Here

        assertEquals("Assert 8:", 4, buf.read());
        assertEquals("Assert 9:", -1, buf.read());

        buf = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 0,
                1, 2, 3, 4 }), 2);
        buf.mark(Integer.MAX_VALUE);
        buf.read();
        buf.close();
    }

    /**
 
View Full Code Here

        assertTrue("Reset failed", new String(buf1, 0, buf1.length)
                .equals(new String(buf2, 0, buf2.length)));

        BufferedInputStream bIn = new BufferedInputStream(
                new ByteArrayInputStream("1234567890".getBytes()));
        bIn.mark(10);
        for (int i = 0; i < 11; i++) {
            bIn.read();
        }
        bIn.reset();
    }
View Full Code Here

        } catch (IOException e) {
            // expected
        }

        // does not throw IOException
        bis.mark(1);
        bis.reset();

        bis.close();

        // throws IOException with message "stream is closed"
View Full Code Here

            byte[] reply = new byte[size];

            // figure out the stream size as we need to pass it in the header
            BufferedInputStream buffer = new BufferedInputStream(data, size);
            try {
                buffer.mark(Integer.MAX_VALUE);
                while ((read = buffer.read(reply)) != -1) {
                    count += read;
                }

                // send the header
View Full Code Here

            InputStream in = httpRequest.getInputStream();
            if (in != null) {
                // use a buffered input stream to find out whether there actually
                // is a request body
                InputStream bin = new BufferedInputStream(in);
                bin.mark(1);
                boolean isEmpty = -1 == bin.read();
                bin.reset();
                if (!isEmpty) {
                    requestDocument = DomUtil.parseDocument(bin);
                }
View Full Code Here

                                 request.getOutputStream());
          request.setOutputStream(bis);
          int cl = request.getContentLength();
          if (cl < 0 )
        cl = 65536;
          bis.mark(cl);
      }
        } else {
      // get only a fresh connection
      while (conn.cached) {
          conn.markIdle(true);
View Full Code Here

    public void testMarkReset() throws IOException {
        File temp = File.createTempFile("test", null);
        TempFileInputStream.writeToFileAndClose(new ByteArrayInputStream(new byte[10]), temp);
        InputStream in = new BufferedInputStream(new TempFileInputStream(temp));
        in.mark(100);
        for (int i = 0; i < 10; i++) {
            assertEquals(0, in.read());
        }
        assertEquals(-1, in.read());
        in.reset();
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.