View Javadoc

1   // ========================================================================
2   // Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.server;
15  
16  import java.io.IOException;
17  
18  import javax.servlet.ServletInputStream;
19  
20  import org.eclipse.jetty.http.HttpParser;
21  import org.eclipse.jetty.io.Buffer;
22  
23  public class HttpInput extends ServletInputStream
24  {
25      protected final HttpParser _parser;
26      protected final long _maxIdleTime;
27      
28      /* ------------------------------------------------------------ */
29      public HttpInput(HttpParser parser, long maxIdleTime)
30      {
31          _parser=parser;
32          _maxIdleTime=maxIdleTime;
33      }
34      
35      /* ------------------------------------------------------------ */
36      /*
37       * @see java.io.InputStream#read()
38       */
39      public int read() throws IOException
40      {
41          int c=-1;
42          Buffer content=_parser.blockForContent(_maxIdleTime);
43          if (content!=null)
44              c= 0xff & content.get();
45          return c;
46      }
47      
48      /* ------------------------------------------------------------ */
49      /* 
50       * @see java.io.InputStream#read(byte[], int, int)
51       */
52      public int read(byte[] b, int off, int len) throws IOException
53      {
54          int l=-1;
55          Buffer content=_parser.blockForContent(_maxIdleTime);
56          if (content!=null)
57              l= content.get(b, off, len);
58          return l;
59      }
60      
61  
62  }