Package java.io

Examples of java.io.PushbackInputStream


   */
  public static InputStream utf8filte(InputStream in) {
    try {
      if (in.available() == -1)
        return in;
      PushbackInputStream pis = new PushbackInputStream(in, 3);
      byte[] header = new byte[3];
      int len = pis.read(header, 0, 3);
      if (len < 1)
        return in;
      if (header[0] != UTF_BOM[0] || header[1] != UTF_BOM[1] || header[2] != UTF_BOM[2]) {
        pis.unread(header, 0, len);
      }
      return pis;
    }
    catch (IOException e) {
      throw Lang.wrapThrow(e);
View Full Code Here


        try {

            Parameter synEnv = messageContext.getConfigurationContext().getAxisConfiguration()
                    .getParameter(SynapseConstants.SYNAPSE_ENV);

            PushbackInputStream pis = detectAndMarkMessageFault(messageContext, inputStream);

            DataHandler dataHandler;
            if (synEnv != null && synEnv.getValue() != null) {
                dataHandler = new DataHandler(new SynapseBinaryDataSource(pis, contentType,
                        (SynapseEnvironment) synEnv.getValue()));
View Full Code Here

     */
    private PushbackInputStream detectAndMarkMessageFault(final MessageContext messageContext,
            final InputStream inputStream) throws IOException {

        int bytesToRead = 4;
        PushbackInputStream pis = new PushbackInputStream(inputStream, bytesToRead);
        byte[] headerBytes = new byte[bytesToRead];
        int n = pis.read(headerBytes);

        // checking fourth byte for fault marker
        if (n == bytesToRead) {
            if (headerBytes[bytesToRead - 1] == HessianConstants.HESSIAN_V1_FAULT_IDENTIFIER
                    || headerBytes[bytesToRead - 1] == HessianConstants.HESSIAN_V2_FAULT_IDENTIFIER) {
                messageContext.setProperty(BaseConstants.FAULT_MESSAGE, SynapseConstants.TRUE);
                if (log.isDebugEnabled()) {
                    log.debug("Hessian fault detected, marking in Axis2 message context");
                }
            }
            pis.unread(headerBytes);
        } else if (n > 0) {
                byte[] bytesRead = new byte[n];
                System.arraycopy(headerBytes, 0, bytesRead, 0, n);
                pis.unread(bytesRead);
        }
        return pis;
    }
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

                if (cli > 0) {
                    in = getInputStream();
                } else if (isChunked || isEofTerminated) {
                    // ensure chunked or EOF-terminated response is non-empty
                    try {
                        @SuppressWarnings("resource")
                        PushbackInputStream pin =
                            new PushbackInputStream(getInputStream());
                        int c = pin.read();
                        if (c != -1) {
                            pin.unread((byte)c);
                            in = pin;
                        }
                    } catch (IOException ioe) {
                        // ignore
                    }   
View Full Code Here

        }
        try {
            ContentType cType = new ContentType(contentType);
            byte[] boundary = ("--" + cType.getParameter("boundary")).getBytes();
            InputStream is = new BufferedInputStream(ds.getInputStream());
            PushbackInputStream pushbackInStream = new PushbackInputStream(is,
                    (boundary.length + 2));
            readTillFirstBoundary(pushbackInStream, boundary);
            while (pushbackInStream.available()>0){
                MimeBodyPartInputStream partStream;
                partStream = new MimeBodyPartInputStream(pushbackInStream,
                        boundary);
                addBodyPart(new MimeBodyPart(partStream));
            }
View Full Code Here

    public EncodingDetectionHelper(InputStream stream) {
        useMark = stream.markSupported();
        if (useMark) {
            this.stream = stream;
        } else {
            this.stream = new PushbackInputStream(stream, 4);
        }
    }
View Full Code Here

                    // 2) Add a push back stream on top of the underlying
                    // source, and unread the surplus bytes we read. Set the
                    // push back stream to be the source of the data input obj.
                    final int surplus = read - hdrInfo.headerLength();
                    FormatIdInputStream formatIn = (FormatIdInputStream)in;
                    PushbackInputStream pushbackIn = new PushbackInputStream(
                            formatIn.getInputStream(), surplus);
                    pushbackIn.unread(header, hdrInfo.headerLength(), surplus);
                    formatIn.setInput(pushbackIn);
                } else {
                    // 3) Assume we have a store stream.
                    rewindStream(srcIn, hdrInfo.headerLength());
                }
View Full Code Here

    private final LittleEndianDataInputStream dataInputStream;

    @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
    public InputStreamSliceInput(InputStream inputStream)
    {
        pushbackInputStream = new PushbackInputStream(inputStream);
        countingInputStream = new CountingInputStream(pushbackInputStream);
        dataInputStream = new LittleEndianDataInputStream(countingInputStream);
    }
View Full Code Here

    protected abstract void readFirstLine(PushbackInputStream r)
            throws IOException;

    public boolean readFrom(InputStream s) {
        PushbackInputStream r = new PushbackInputStream(s);

        try {
            readFirstLine(r);
            readHeaders(r);
            return readBody(s);
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.