Package org.browsermob.proxy.jetty.util

Examples of org.browsermob.proxy.jetty.util.LineInput$ByteBuffer


        // hook processes output to browser's input (sync)
        // if browser closes stream, we should detect it and kill process...
        try
        {
            // read any headers off the top of our input stream
            LineInput li = new LineInput(p.getInputStream());
            HttpFields fields=new HttpFields();
            fields.read(li);

            String ContentStatus = "Status";
            String redirect = fields.get(HttpFields.__Location);
View Full Code Here


        if(srequest.getContentType()==null||!srequest.getContentType().startsWith("multipart/form-data"))
        {
            chain.doFilter(request,response);
            return;
        }
        LineInput in=new LineInput(request.getInputStream());
        String content_type=srequest.getContentType();
        String boundary="--"+value(content_type.substring(content_type.indexOf("boundary=")));
        byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
        MultiMap params = new MultiMap();
       
        // Get first boundary
        String line=in.readLine();
        if(!line.equals(boundary))
        {
            log.warn(line);
            throw new IOException("Missing initial multi part boundary");
        }
       
        // Read each part
        boolean lastPart=false;
        String content_disposition=null;
        while(!lastPart)
        {
            while((line=in.readLine())!=null)
            {
                // If blank line, end of part headers
                if(line.length()==0)
                    break;
                // place part header key and value in map
                int c=line.indexOf(':',0);
                if(c>0)
                {
                    String key=line.substring(0,c).trim().toLowerCase();
                    String value=line.substring(c+1,line.length()).trim();
                    if(key.equals("content-disposition"))
                        content_disposition=value;
                }
            }
            // Extract content-disposition
            boolean form_data=false;
            if(content_disposition==null)
            {
                throw new IOException("Missing content-disposition");
            }
           
            StringTokenizer tok=new StringTokenizer(content_disposition,";");
            String name=null;
            String filename=null;
            while(tok.hasMoreTokens())
            {
                String t=tok.nextToken().trim();
                String tl=t.toLowerCase();
                if(t.startsWith("form-data"))
                    form_data=true;
                else if(tl.startsWith("name="))
                    name=value(t);
                else if(tl.startsWith("filename="))
                    filename=value(t);
            }
           
            // Check disposition
            if(!form_data)
            {
                log.warn("Non form-data part in multipart/form-data");
                continue;
            }
            if(name==null||name.length()==0)
            {
                log.warn("Part with no name in multipart/form-data");
                continue;
            }
           
            OutputStream out=null;
            File file=null;
            try
            {
                if (filename!=null && filename.length()>0)
                {
                    file = File.createTempFile("MultiPart", "", tempdir);
                    out = new FileOutputStream(file);
                    request.setAttribute(name,file);
                    params.put(name, filename);
                }
                else
                    out=new ByteArrayOutputStream();
               
                int state=-2;
                int c;
                boolean cr=false;
                boolean lf=false;
               
                // loop for all lines`
                while(true)
                {
                    int b=0;
                    while((c=(state!=-2)?state:in.read())!=-1)
                    {
                        state=-2;
                        // look for CR and/or LF
                        if(c==13||c==10)
                        {
                            if(c==13)
                                state=in.read();
                            break;
                        }
                        // look for boundary
                        if(b>=0&&b<byteBoundary.length&&c==byteBoundary[b])
                            b++;
View Full Code Here

    /* ------------------------------------------------------------ */
    public AJP13Connection(AJP13Listener listener, InputStream in, OutputStream out, Socket socket, int bufferSize) throws IOException
    {
        super(listener,null,new AJP13InputStream(in,out,bufferSize),out,socket);

        LineInput lin=(LineInput)getInputStream().getInputStream();
        _ajpIn=(AJP13InputStream)lin.getInputStream();
        _ajpOut=new AJP13OutputStream(getOutputStream().getOutputStream(),bufferSize);
        _ajpOut.setCommitObserver(this);
        getOutputStream().setBufferedOutputStream(_ajpOut);
        _listener=listener;
    }
View Full Code Here

     */
    public HttpInputStream(InputStream in, int bufferSize)
    {
        super(null);
        try {
            _realIn= new LineInput(in,bufferSize,StringUtil.__ISO_8859_1);
        }
        catch(UnsupportedEncodingException e)
        {
            log.fatal(e); System.exit(1);
        }
View Full Code Here

      return charBuffer.getWriter();
   }

   public OutputStream getPortletOutputStream() throws IOException
   {
      ByteBuffer byteBuffer;
      if (buffer != null)
      {
         if (buffer instanceof ByteBuffer)
         {
            byteBuffer = (ByteBuffer)buffer;
         }
         else
         {
            throw new IllegalStateException("The method getWriter() was already called");
         }
      }
      else
      {
         buffer = byteBuffer = new ByteBuffer();
      }
      return byteBuffer.getOutputStream();
   }
View Full Code Here

TOP

Related Classes of org.browsermob.proxy.jetty.util.LineInput$ByteBuffer

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.