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 @Override 40 public int read() throws IOException 41 { 42 int c=-1; 43 Buffer content=_parser.blockForContent(_maxIdleTime); 44 if (content!=null) 45 c= 0xff & content.get(); 46 return c; 47 } 48 49 /* ------------------------------------------------------------ */ 50 /* 51 * @see java.io.InputStream#read(byte[], int, int) 52 */ 53 @Override 54 public int read(byte[] b, int off, int len) throws IOException 55 { 56 int l=-1; 57 Buffer content=_parser.blockForContent(_maxIdleTime); 58 if (content!=null) 59 l= content.get(b, off, len); 60 return l; 61 } 62 63 /* ------------------------------------------------------------ */ 64 @Override 65 public int available() throws IOException 66 { 67 return _parser.available(); 68 } 69 70 71 72 73 }