Package java.io

Examples of java.io.BufferedInputStream.mark()


        }
    InputStream in = new BufferedInputStream(
        new ByteArrayInputStream(bytes), 12);
    try {
      in.skip(6);
      in.mark(14);
      in.read(new byte[14], 0, 14);
      in.reset();
      assertTrue("Wrong bytes", in.read() == 6 && in.read() == 7);
    } catch (IOException e) {
      fail("Exception during mark test 2");
View Full Code Here


    }

    in = new BufferedInputStream(new ByteArrayInputStream(bytes), 12);
    try {
      in.skip(6);
      in.mark(8);
      in.skip(7);
      in.reset();
      assertTrue("Wrong bytes 2", in.read() == 6 && in.read() == 7);
    } catch (IOException e) {
      fail("Exception during mark test 3");
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

            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) {
                    DocumentBuilder docBuilder = DomUtil.BUILDER_FACTORY.newDocumentBuilder();
                    requestDocument = docBuilder.parse(bin);
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

                    if (x < 0) {
                        break;
                    }
                    if (x == (pattern[patternPos] & 0xff)) {
                        if (patternPos == 0) {
                            in.mark(pattern.length);
                        }
                        if (patternPos == pattern.length) {
                            return pos - patternPos;
                        }
                        patternPos++;
View Full Code Here

        boolean isShout = false;
        int toRead = 4;
        byte[] head = new byte[toRead];
        conn.setRequestProperty("Icy-Metadata", "1");
        BufferedInputStream bInputStream = new BufferedInputStream(conn.getInputStream());
        bInputStream.mark(toRead);
        int read = bInputStream.read(head, 0, toRead);
        if ((read > 2) && (((head[0] == 'I') | (head[0] == 'i')) && ((head[1] == 'C') | (head[1] == 'c')) && ((head[2] == 'Y') | (head[2] == 'y')))) isShout = true;
        bInputStream.reset();
        InputStream inputStream = null;
        // Is is a shoutcast server ?
View Full Code Here

      // start with the header of BZ. So it works fine either we have
      // the header or not.
      BufferedInputStream bufferedIn = null;
      if (super.in != null) {
        bufferedIn = new BufferedInputStream(super.in);
        bufferedIn.mark(HEADER_LEN);
        byte[] headerBytes = new byte[HEADER_LEN];
        int actualRead = bufferedIn.read(headerBytes, 0, HEADER_LEN);
        if (actualRead != -1) {
          String header = new String(headerBytes);
          if (header.compareTo(HEADER) != 0) {
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) {
                    DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder();
                    requestDocument = docBuilder.parse(bin);
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.