diff src/org/eclipse/jetty/server/AbstractHttpConnection.java @ 981:f46de416e219

remove HttpInput
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 16 Oct 2016 21:10:25 -0600
parents bd26bd9320e2
children dbecd7faa1f5
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java	Sun Oct 16 21:01:26 2016 -0600
+++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java	Sun Oct 16 21:10:25 2016 -0600
@@ -177,7 +177,7 @@
 		}
 
 		if (_in == null)
-			_in = new HttpInput(AbstractHttpConnection.this);
+			_in = new HttpInput();
 		return _in;
 	}
 
@@ -226,11 +226,6 @@
 		return _printWriter;
 	}
 
-	public final boolean isEarlyEOF()
-	{
-		return _earlyEOF;
-	}
-
 	protected void reset()
 	{
 		_parser.reset();
@@ -772,13 +767,11 @@
 			writer.print(s);
 		}
 
-		/* ------------------------------------------------------------ */
 		public void sendResponse(Buffer response) throws IOException
 		{
 			((HttpGenerator)super._generator).sendResponse(response);
 		}
 
-		/* ------------------------------------------------------------ */
 		public void sendContent(Object content) throws IOException
 		{
 			Resource resource=null;
@@ -835,8 +828,44 @@
 			}
 			else
 				throw new IllegalArgumentException("unknown content type?");
+		}
+	}
 
 
+	private final class HttpInput extends ServletInputStream
+	{
+		/* ------------------------------------------------------------ */
+		/*
+		 * @see java.io.InputStream#read()
+		 */
+		@Override
+		public int read() throws IOException
+		{
+			byte[] bytes = new byte[1];
+			int read = read(bytes, 0, 1);
+			return read < 0 ? -1 : 0xff & bytes[0];
+		}
+		
+		/* ------------------------------------------------------------ */
+		/* 
+		 * @see java.io.InputStream#read(byte[], int, int)
+		 */
+		@Override
+		public int read(byte[] b, int off, int len) throws IOException
+		{
+			int l = -1;
+			Buffer content = _parser.blockForContent(getMaxIdleTime());
+			if (content!=null)
+				l = content.get(b, off, len);
+			else if (_earlyEOF)
+				throw new EofException("early EOF");
+			return l;
+		}
+	
+		@Override
+		public int available() throws IOException
+		{
+			return _parser.available();
 		}
 	}