Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 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.http;
 
 
 
 /* ------------------------------------------------------------ */
HttpContent.
 
 public interface HttpContent
 {
     Buffer getContentType();
     Resource getResource();
     long getContentLength();
     void release();
     
     /* ------------------------------------------------------------ */
     /* ------------------------------------------------------------ */
     /* ------------------------------------------------------------ */
     public class ResourceAsHttpContent implements HttpContent
     {
         private static final Logger LOG = Log.getLogger(ResourceAsHttpContent.class);
         
         final Resource _resource;
         final Buffer _mimeType;
         final int _maxBuffer;
 
         public ResourceAsHttpContent(final Resource resourcefinal Buffer mimeType)
         {
             =resource;
             =mimeType;
             =-1;
         }
         
         public ResourceAsHttpContent(final Resource resourcefinal Buffer mimeTypeint maxBuffer)
         {
             =resource;
             =mimeType;
             =maxBuffer;
         }
 
         /* ------------------------------------------------------------ */
         public Buffer getContentType()
         {
             return ;
         }
 
         /* ------------------------------------------------------------ */
         public Buffer getLastModified()
         {
             return null;
         }
 
         /* ------------------------------------------------------------ */
         public Buffer getDirectBuffer()
         {
             return null;
         }
 
         /* ------------------------------------------------------------ */
         public Buffer getIndirectBuffer()
         {
             InputStream inputStream = null;
             try
             {
                 if (.length() <= 0 ||  < .length())
                     return null;
                 ByteArrayBuffer buffer = new ByteArrayBuffer((int).length());
                 inputStream = .getInputStream();
                 buffer.readFrom(inputStream,(int).length());
                return buffer;
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            finally
            {
                if (inputStream != null)
                {
                    try
                    {
                        inputStream.close();
                    }
                    catch (IOException e)
                    {
                        .warn("Couldn't close inputStream. Possible file handle leak",e);
                    }
                }
            }
        }
        /* ------------------------------------------------------------ */
        public long getContentLength()
        {
            return .length();
        }
        /* ------------------------------------------------------------ */
        public InputStream getInputStream() throws IOException
        {
            return .getInputStream();
        }
        /* ------------------------------------------------------------ */
        public Resource getResource()
        {
            return ;
        }
        /* ------------------------------------------------------------ */
        public void release()
        {
            .release();
        }
    }
New to GrepCode? Check out our FAQ X