comparison src/org/eclipse/jetty/server/HttpInput.java @ 972:5ee36654b383

simplify AbstractHttpConnection
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 Oct 2016 22:42:05 -0600
parents 3428c60d7cfc
children bd26bd9320e2
comparison
equal deleted inserted replaced
971:f997df37cec1 972:5ee36654b383
26 import org.eclipse.jetty.io.Buffer; 26 import org.eclipse.jetty.io.Buffer;
27 import org.eclipse.jetty.io.EofException; 27 import org.eclipse.jetty.io.EofException;
28 28
29 public class HttpInput extends ServletInputStream 29 public class HttpInput extends ServletInputStream
30 { 30 {
31 protected final AbstractHttpConnection _connection; 31 protected final AbstractHttpConnection _connection;
32 protected final HttpParser _parser; 32 protected final HttpParser _parser;
33 33
34 /* ------------------------------------------------------------ */ 34 public HttpInput(AbstractHttpConnection connection)
35 public HttpInput(AbstractHttpConnection connection) 35 {
36 { 36 _connection = connection;
37 _connection=connection; 37 _parser = connection._parser;
38 _parser=(HttpParser)connection.getParser(); 38 }
39 } 39
40 40 /* ------------------------------------------------------------ */
41 /* ------------------------------------------------------------ */ 41 /*
42 /* 42 * @see java.io.InputStream#read()
43 * @see java.io.InputStream#read() 43 */
44 */ 44 @Override
45 @Override 45 public int read() throws IOException
46 public int read() throws IOException 46 {
47 { 47 byte[] bytes = new byte[1];
48 byte[] bytes = new byte[1]; 48 int read = read(bytes, 0, 1);
49 int read = read(bytes, 0, 1); 49 return read < 0 ? -1 : 0xff & bytes[0];
50 return read < 0 ? -1 : 0xff & bytes[0]; 50 }
51 } 51
52 52 /* ------------------------------------------------------------ */
53 /* ------------------------------------------------------------ */ 53 /*
54 /* 54 * @see java.io.InputStream#read(byte[], int, int)
55 * @see java.io.InputStream#read(byte[], int, int) 55 */
56 */ 56 @Override
57 @Override 57 public int read(byte[] b, int off, int len) throws IOException
58 public int read(byte[] b, int off, int len) throws IOException 58 {
59 { 59 int l=-1;
60 int l=-1; 60 Buffer content=_parser.blockForContent(_connection.getMaxIdleTime());
61 Buffer content=_parser.blockForContent(_connection.getMaxIdleTime()); 61 if (content!=null)
62 if (content!=null) 62 l= content.get(b, off, len);
63 l= content.get(b, off, len); 63 else if (_connection.isEarlyEOF())
64 else if (_connection.isEarlyEOF()) 64 throw new EofException("early EOF");
65 throw new EofException("early EOF"); 65 return l;
66 return l; 66 }
67 }
68 67
69 /* ------------------------------------------------------------ */ 68 /* ------------------------------------------------------------ */
70 @Override 69 @Override
71 public int available() throws IOException 70 public int available() throws IOException
72 { 71 {
73 return _parser.available(); 72 return _parser.available();
74 } 73 }
75 } 74 }