Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.io;
 
 /* ------------------------------------------------------------ */
SimpleBuffers. Simple implementation of Buffers holder.
 
 public class SimpleBuffers implements Buffers
 {   
     final Buffer _header;
     final Buffer _buffer;
     boolean _headerOut;
     boolean _bufferOut;
     
     /* ------------------------------------------------------------ */
    
 
     public SimpleBuffers(Buffer headerBuffer buffer)
     {
         =header;
         =buffer;
     }
 
     /* ------------------------------------------------------------ */
     public Buffer getBuffer()
     {
         synchronized(this)
         {
             if (!=null && !)
             {
                 =true;
                 return ;
             }
             
             if (!=null && !=null && .capacity()==.capacity() && !)
             {
                 =true;
                 return ;
             }
             
             if (!=null)
                 return new ByteArrayBuffer(.capacity());
             return new ByteArrayBuffer(4096);
         }
     }
 
     /* ------------------------------------------------------------ */
     public Buffer getHeader()
     {
         synchronized(this)
         {
             if (!=null && !)
             {
                 =true;
                 return ;
             }
             
             if (!=null && !=null && .capacity()==.capacity() && !)
             {
                 =true;
                 return ;
             }
             
             if (!=null)
                 return new ByteArrayBuffer(.capacity());
             return new ByteArrayBuffer(4096);
         }
     }
 
     /* ------------------------------------------------------------ */
     public Buffer getBuffer(int size)
     {
         synchronized(this)
         {
             if (!=null && .capacity()==size)
                 return getHeader();
             if (!=null && .capacity()==size)
                 return getBuffer();
             return null;            
        }
    }
    /* ------------------------------------------------------------ */
    public void returnBuffer(Buffer buffer)
    {
        synchronized(this)
        {
            buffer.clear();
            if (buffer==)
                =false;
            if (buffer==)
                =false;
        }
    }
New to GrepCode? Check out our FAQ X