changeset 1064:a0abb16cf6e7

remove JBuffer.readFrom()
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 09 Nov 2016 03:09:37 -0700
parents 0157e92670f5
children 158d1e6ac17f
files src/org/eclipse/jetty/http/HttpGenerator.java src/org/eclipse/jetty/io/JBuffer.java src/org/eclipse/jetty/server/AbstractHttpConnection.java
diffstat 3 files changed, 34 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
diff -r 0157e92670f5 -r a0abb16cf6e7 src/org/eclipse/jetty/http/HttpGenerator.java
--- a/src/org/eclipse/jetty/http/HttpGenerator.java	Wed Nov 09 02:08:33 2016 -0700
+++ b/src/org/eclipse/jetty/http/HttpGenerator.java	Wed Nov 09 03:09:37 2016 -0700
@@ -200,34 +200,32 @@
 	 * @return the available space in the buffer.
 	 * @throws IOException
 	 */
-	public int prepareUncheckedAddContent() throws IOException
+	public void prepareUncheckedAddContent() throws IOException
 	{
 		if (_noContent)
-			return -1;
+//			return -1;
+			throw new RuntimeException("_noContent");
 
 		if (_last || _state==STATE_END)
-			return -1;
+//			return -1;
+			throw new RuntimeException("_last");
 
 		// Handle any unfinished business?
-		JBuffer content = _content;
-		if (content != null && content.remaining()>0 || _bufferChunked)
+		if (_content != null && _content.remaining()>0 || _bufferChunked)
 		{
 			flushBuffer();
-			if (content != null && content.remaining()>0 || _bufferChunked)
+			if (_content != null && _content.remaining()>0 || _bufferChunked)
 				throw new IllegalStateException("FULL");
 		}
 
-		// we better check we have a buffer
-		if (_buffer == null)
-			_buffer = _buffers.getBuffer();
-
-		_contentWritten-=_buffer.remaining();
-
+		_contentWritten -= _buffer.remaining();
+/*
 		// Handle the _content
 		if (_head)
 			return Integer.MAX_VALUE;
 
 		return _buffer.space();
+*/
 	}
 
 	public boolean isBufferFull()
@@ -976,6 +974,8 @@
 
 	public final JBuffer getUncheckedBuffer()
 	{
+		if (_buffer == null)
+			_buffer = _buffers.getBuffer();
 		return _buffer;
 	}
 
@@ -1064,17 +1064,9 @@
 
 	public final void completeUncheckedAddContent()
 	{
-		if (_noContent)
-		{
-			if(_buffer!=null)
-				_buffer.clear();
-		}
-		else
-		{
-			_contentWritten += _buffer.remaining();
-			if (_head)
-				_buffer.clear();
-		}
+		_contentWritten += _buffer.remaining();
+		if (_head)
+			_buffer.clear();
 	}
 
 	private boolean isBufferFull2()
diff -r 0157e92670f5 -r a0abb16cf6e7 src/org/eclipse/jetty/io/JBuffer.java
--- a/src/org/eclipse/jetty/io/JBuffer.java	Wed Nov 09 02:08:33 2016 -0700
+++ b/src/org/eclipse/jetty/io/JBuffer.java	Wed Nov 09 03:09:37 2016 -0700
@@ -5,8 +5,6 @@
 import java.io.InputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.eclipse.jetty.util.TypeUtil;
@@ -144,33 +142,19 @@
 		bb.position(bb.position() + n);
 	}
 
-	public int readFrom(InputStream in,int max) throws IOException {
-		ByteBuffer dup = bb.duplicate();
-		int put = bb.limit();
-		dup.limit( Math.min(put+max,bb.capacity()) );
-		dup.position(put);
-
-		ReadableByteChannel chan = Channels.newChannel(in);
-		int n = chan.read(dup);
-
-		if( n > 0 )
-			bb.limit(put+n);
-		return n;
-	}
-
 	private final byte[] asArray() {
 		byte[] bytes = new byte[remaining()];
 		bb.duplicate().get(bytes);
 		return bytes;
 	}
-
+/*
 	@Override
 	public String toString() {
 //		return toString("ISO-8859-1");
 //		Thread.dumpStack();
 		throw new RuntimeException("toString");
 	}
-
+*/
 
 	public byte get(int index) {
 		return bb.get(index);
diff -r 0157e92670f5 -r a0abb16cf6e7 src/org/eclipse/jetty/server/AbstractHttpConnection.java
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java	Wed Nov 09 02:08:33 2016 -0700
+++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java	Wed Nov 09 03:09:37 2016 -0700
@@ -22,6 +22,9 @@
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
 
 import javax.servlet.ServletInputStream;
 import javax.servlet.ServletOutputStream;
@@ -833,22 +836,28 @@
 
 			try
 			{
-				int max = _generator.prepareUncheckedAddContent();
+				ReadableByteChannel chan = Channels.newChannel(in);
 				JBuffer buffer = _generator.getUncheckedBuffer();
+				ByteBuffer dup = buffer.getByteBuffer().duplicate();
+				dup.limit(dup.capacity());
 
-				int len = buffer.readFrom(in,max);
+				while (true)
+				{
+					_generator.prepareUncheckedAddContent();
 
-				while (len>=0)
-				{
+					dup.position(buffer.limit());
+					int n = chan.read(dup);
+					if( n == -1 )
+						break;
+					buffer.limit(dup.position());
+
 					_generator.completeUncheckedAddContent();
 					_out.flush();
-
-					max = _generator.prepareUncheckedAddContent();
-					buffer = _generator.getUncheckedBuffer();
-					len = buffer.readFrom(in,max);
 				}
+/*
 				_generator.completeUncheckedAddContent();
 				_out.flush();
+*/
 			}
 			finally
 			{
@@ -857,7 +866,6 @@
 		}
 	}
 
-
 	private final class HttpInput extends ServletInputStream
 	{
 		/* ------------------------------------------------------------ */