Package java.io

Examples of java.io.PushbackInputStream


        IOUtils.readFully(inp, header);
        LongField signature = new LongField(HeaderBlockConstants._signature_offset, header);

        // Wind back those 8 bytes
        if(inp instanceof PushbackInputStream) {
            PushbackInputStream pin = (PushbackInputStream)inp;
            pin.unread(header);
        } else {
            inp.reset();
        }
       
        // Did it match the signature?
View Full Code Here


   * Takens an InputStream, verifies that it's not RTF, builds a
   *  POIFSFileSystem from it, and returns that.
   */
  public static POIFSFileSystem verifyAndBuildPOIFS(InputStream istream) throws IOException {
  // Open a PushbackInputStream, so we can peek at the first few bytes
  PushbackInputStream pis = new PushbackInputStream(istream,6);
  byte[] first6 = new byte[6];
  pis.read(first6);

  // Does it start with {\rtf ? If so, it's really RTF
  if(first6[0] == '{' && first6[1] == '\\' && first6[2] == 'r'
    && first6[3] == 't' && first6[4] == 'f') {
    throw new IllegalArgumentException("The document is really a RTF file");
  }

  // OK, so it's not RTF
  // Open a POIFSFileSystem on the (pushed back) stream
  pis.unread(first6);
  return new POIFSFileSystem(pis);
  }
View Full Code Here

      byte[] reqBytes= reqStr.toString().getBytes();

      req.write(reqBytes);
      req.flush();
       
      PushbackInputStream in =                  // process response
        new PushbackInputStream(
          new BufferedInputStream(socket.getInputStream(), Http.BUFFER_SIZE),
          Http.BUFFER_SIZE) ;

      StringBuffer line = new StringBuffer();
View Full Code Here

            if (encoding == null || encoding.toLowerCase().indexOf("utf") != -1) {
                byte bom[] = new byte[4];
                int unread;

                // auto-detect byte-order-mark
                @SuppressWarnings("resource")
                PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream, bom.length);
                int n = pushbackInputStream.read(bom, 0, bom.length);

                // Read ahead four bytes and check for BOM marks.
                if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
                    encoding = "UTF-8";
                    unread = n - 3;
                } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
                    encoding = "UTF-16BE";
                    unread = n - 2;
                } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
                    encoding = "UTF-16LE";
                    unread = n - 2;
                } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
                        && (bom[3] == (byte) 0xFF)) {
                    encoding = "UTF-32BE";
                    unread = n - 4;
                } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
                        && (bom[3] == (byte) 0x00)) {
                    encoding = "UTF-32LE";
                    unread = n - 4;
                } else {
                    unread = n;
                }

                if (unread > 0) {
                    pushbackInputStream.unread(bom, (n - unread), unread);
                } else if (unread < -1) {
                    pushbackInputStream.unread(bom, 0, 0);
                }

                inputStream = pushbackInputStream;
            }
View Full Code Here

    }

    private InputStream getInputStream() throws MetaModelException {
        InputStream inputStream = _resource.read();
        if (!inputStream.markSupported()) {
            inputStream = new PushbackInputStream(inputStream, 8);
        }
        return inputStream;
    }
View Full Code Here

        IOUtils.readFully(inp, header);
        LongField signature = new LongField(HeaderBlockConstants._signature_offset, header);

        // Wind back those 8 bytes
        if(inp instanceof PushbackInputStream) {
            PushbackInputStream pin = (PushbackInputStream)inp;
            pin.unread(header);
        } else {
            inp.reset();
        }

        // Did it match the signature?
View Full Code Here

     * @since 1.3
     */
    public XmlHeaderAwareReader(final InputStream in) throws UnsupportedEncodingException, IOException {
        final PushbackInputStream[] pin = new PushbackInputStream[]{in instanceof PushbackInputStream
            ? (PushbackInputStream)in
            : new PushbackInputStream(in, 64)};
        final Map<String, String> header = getHeader(pin);
        version = Double.parseDouble(header.get(KEY_VERSION));
        reader = new InputStreamReader(pin[0], header.get(KEY_ENCODING));
    }
View Full Code Here

        for (i = pushbackData.length; i-- > 0;) {
            final byte b = pushbackData[i];
            try {
                in[0].unread(b);
            } catch (final IOException ex) {
                in[0] = new PushbackInputStream(in[0], ++i);
            }
        }
        return header;
    }
View Full Code Here

        }

        if (in instanceof PushbackInputStream) {
            this.in = (PushbackInputStream) in;
        } else {
            this.in = new PushbackInputStream(in);
        }
        this.chunkSize = chunkSize;
    }
View Full Code Here

  private int line;
 
  private int column;
 
  public JSMin(InputStream in, OutputStream out) {
    this.in = new PushbackInputStream(in);
    this.out = out;
    this.line = 0;
    this.column = 0;
  }
View Full Code Here

TOP

Related Classes of java.io.PushbackInputStream

Copyright © 2018 www.massapicom. 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.