Package java.io

Examples of java.io.PushbackInputStream


 
  public static POITextExtractor createExtractor(InputStream inp) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
    // Figure out the kind of stream
    // If clearly doesn't do mark/reset, wrap up
    if(! inp.markSupported()) {
      inp = new PushbackInputStream(inp, 8);
    }
   
    if(POIFSFileSystem.hasPOIFSHeader(inp)) {
      return createExtractor(new POIFSFileSystem(inp));
    }
View Full Code Here


    if (!(type != null && MimeTypeHelper.isAtom(type))) {
      throw new ParseException("multipart/related stream invalid, type parameter should be "
              + Constants.ATOM_MEDIA_TYPE);
    }

    PushbackInputStream pushBackInput = new PushbackInputStream(request.getInputStream(), 2);
    pushBackInput.unread("\r\n".getBytes());

    return new MultipartInputStream(pushBackInput, boundary.getBytes());
  }
View Full Code Here

     *
     * @see <a href="http://jira.springframework.org/browse/SWS-393">SWS-393</a>
     * @see <a href="http://unicode.org/faq/utf_bom.html#22">UTF-8 BOMs</a>
     */
    private InputStream checkForUtf8ByteOrderMark(InputStream inputStream) throws IOException {
        PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3);
        byte[] bytes = new byte[3];
        int bytesRead = 0;
      while (bytesRead < bytes.length) {
        int n = pushbackInputStream.read(bytes, bytesRead, bytes.length - bytesRead);
        if (n > 0) {
          bytesRead += n;
        } else {
          break;
        }
      }
        if (bytesRead > 0) {
            // check for the UTF-8 BOM, and remove it if there. See SWS-393
            if (!isByteOrderMark(bytes)) {
                pushbackInputStream.unread(bytes, 0, bytesRead);
            }
        }
        return pushbackInputStream;
    }
View Full Code Here

  protected byte[] buffer;
  protected int pos;
  protected boolean rewindable;
 
  public RewindableInputStream(InputStream input, int size) {
    this.wrappedStream = new PushbackInputStream(input, size);
    this.buffer = new byte[size];
    this.pos = 0;
    this.rewindable = true;
  }
View Full Code Here

        if (TDebug.TraceAudioFileReader) TDebug.out(">MpegAudioFileReader.getAudioFileFormat(InputStream inputStream, long mediaLength): begin");
        HashMap aff_properties = new HashMap();
        HashMap af_properties = new HashMap();
        int mLength = (int) mediaLength;
        int size = inputStream.available();
        PushbackInputStream pis = new PushbackInputStream(inputStream, MARK_LIMIT);
        byte head[] = new byte[22];
        pis.read(head);
        if (TDebug.TraceAudioFileReader)
        {
            TDebug.out("InputStream : " + inputStream + " =>" + new String(head));
        }

        // Check for WAV, AU, and AIFF, Ogg Vorbis, Flac, MAC file formats.
        // Next check for Shoutcast (supported) and OGG (unsupported) streams.
        if ((head[0] == 'R') && (head[1] == 'I') && (head[2] == 'F') && (head[3] == 'F') && (head[8] == 'W') && (head[9] == 'A') && (head[10] == 'V') && (head[11] == 'E'))
        {
            if (TDebug.TraceAudioFileReader) TDebug.out("RIFF/WAV stream found");
            int isPCM = ((head[21]<<8)&0x0000FF00) | ((head[20])&0x00000FF);
            if (weak == null)
            {
                if (isPCM == 1) throw new UnsupportedAudioFileException("WAV PCM stream found");
            }

        }
        else if ((head[0] == '.') && (head[1] == 's') && (head[2] == 'n') && (head[3] == 'd'))
        {
            if (TDebug.TraceAudioFileReader) TDebug.out("AU stream found");
            if (weak == null) throw new UnsupportedAudioFileException("AU stream found");
        }
        else if ((head[0] == 'F') && (head[1] == 'O') && (head[2] == 'R') && (head[3] == 'M') && (head[8] == 'A') && (head[9] == 'I') && (head[10] == 'F') && (head[11] == 'F'))
        {
            if (TDebug.TraceAudioFileReader) TDebug.out("AIFF stream found");
            if (weak == null) throw new UnsupportedAudioFileException("AIFF stream found");
        }
        else if (((head[0] == 'M') | (head[0] == 'm')) && ((head[1] == 'A') | (head[1] == 'a')) && ((head[2] == 'C') | (head[2] == 'c')))
        {
            if (TDebug.TraceAudioFileReader) TDebug.out("APE stream found");
            if (weak == null) throw new UnsupportedAudioFileException("APE stream found");
        }
        else if (((head[0] == 'F') | (head[0] == 'f')) && ((head[1] == 'L') | (head[1] == 'l')) && ((head[2] == 'A') | (head[2] == 'a')) && ((head[3] == 'C') | (head[3] == 'c')))
        {
            if (TDebug.TraceAudioFileReader) TDebug.out("FLAC stream found");
            if (weak == null) throw new UnsupportedAudioFileException("FLAC stream found");
        }
        // Shoutcast stream ?
        else if (((head[0] == 'I') | (head[0] == 'i')) && ((head[1] == 'C') | (head[1] == 'c')) && ((head[2] == 'Y') | (head[2] == 'y')))
        {
            pis.unread(head);
            // Load shoutcast meta data.
            loadShoutcastInfo(pis, aff_properties);
        }
        // Ogg stream ?
        else if (((head[0] == 'O') | (head[0] == 'o')) && ((head[1] == 'G') | (head[1] == 'g')) && ((head[2] == 'G') | (head[2] == 'g')))
        {
            if (TDebug.TraceAudioFileReader) TDebug.out("Ogg stream found");
            if (weak == null) throw new UnsupportedAudioFileException("Ogg stream found");
        }
        // No, so pushback.
        else
        {
            pis.unread(head);
        }
        // MPEG header info.
        int nVersion = AudioSystem.NOT_SPECIFIED;
        int nLayer = AudioSystem.NOT_SPECIFIED;
        int nSFIndex = AudioSystem.NOT_SPECIFIED;
View Full Code Here

            if (null == boundaryString) {
                throw new IOException("Couldn't determine the boundary from the message!");
            }
            boundary = boundaryString.getBytes("utf-8");

            stream = new PushbackInputStream(message.getContent(InputStream.class),
                                             pbAmount);
            if (!readTillFirstBoundary(stream, boundary)) {
                throw new IOException("Couldn't find MIME boundary: " + boundaryString);
            }
View Full Code Here

    }

    private String findBoundaryFromInputStream() throws IOException {
        InputStream is = message.getContent(InputStream.class);
        //boundary should definitely be in the first 2K;
        PushbackInputStream in = new PushbackInputStream(is, 4096);
        byte buf[] = new byte[2048];
        int i = in.read(buf);
        String msg = IOUtils.newStringFromBytes(buf, 0, i);
        in.unread(buf, 0, i);
       
        // Reset the input stream since we'll need it again later
        message.setContent(InputStream.class, in);

        // Use regex to get the boundary and return null if it's not found
View Full Code Here

    private static InputStream getNonEmptyContent(
        HttpURLConnection connection
    ) {
        InputStream in = null;
        try {
            PushbackInputStream pin =
                new PushbackInputStream(connection.getInputStream());
            int c = pin.read();
            if (c != -1) {
                pin.unread((byte)c);
                in = pin;
            }
        } catch (IOException ioe) {
            // ignore
        }   
View Full Code Here

    private String resourceName;
   
    public ValueExpressionFilterInputStream(InputStream in, String libraryName, String resourceName)
    {
        super();
        delegate = new PushbackInputStream(in,255);
    }
View Full Code Here

        this.boundary = ("--" + contentType.getParameter("boundary"))
                .getBytes();

        // do we need to wrap InputStream from a BufferedInputStream before
        // wrapping from PushbackStream
        pushbackInStream = new PushbackInputStream(inStream,
                                                   (this.boundary.length + 2));

        // Move the read pointer to the beginning of the first part
        // read till the end of first boundary
        while (true) {
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.