diff src/org/eclipse/jetty/io/nio/ChannelEndPoint.java @ 1048:2b769da7f67d

remove Buffer
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 07 Nov 2016 23:15:42 -0700
parents a8c92b0a08ed
children 4afdf0f0c5bc
line wrap: on
line diff
--- a/src/org/eclipse/jetty/io/nio/ChannelEndPoint.java	Mon Nov 07 22:51:09 2016 -0700
+++ b/src/org/eclipse/jetty/io/nio/ChannelEndPoint.java	Mon Nov 07 23:15:42 2016 -0700
@@ -27,7 +27,7 @@
 import java.nio.channels.GatheringByteChannel;
 import java.nio.channels.SocketChannel;
 
-import org.eclipse.jetty.io.Buffer;
+import org.eclipse.jetty.io.JBuffer;
 import org.eclipse.jetty.io.EndPoint;
 import org.eclipse.jetty.util.StringUtil;
 import org.slf4j.Logger;
@@ -164,116 +164,93 @@
 	}
 
 	@Override
-	public int fill(Buffer buffer) throws IOException
+	public int fill(JBuffer buffer) throws IOException
 	{
 		if (_ishut)
 			return -1;
-		Buffer buf = buffer.buffer();
+		JBuffer nbuf = buffer.buffer();
 		int len = 0;
-		if (buf instanceof NIOBuffer)
+		final ByteBuffer bbuf = nbuf.getByteBuffer();
+
+		//noinspection SynchronizationOnLocalVariableOrMethodParameter
+		try
 		{
-			final NIOBuffer nbuf = (NIOBuffer)buf;
-			final ByteBuffer bbuf = nbuf.getByteBuffer();
+			synchronized(bbuf)
+			{
+				try
+				{
+					bbuf.position(buffer.putIndex());
+					len = _channel.read(bbuf);
+				}
+				finally
+				{
+					buffer.setPutIndex(bbuf.position());
+					bbuf.position(0);
+				}
+			}
 
-			//noinspection SynchronizationOnLocalVariableOrMethodParameter
+			if (len<0 && isOpen())
+			{
+				if (!isInputShutdown())
+					shutdownInput();
+				if (isOutputShutdown())
+					_channel.close();
+			}
+		}
+		catch (IOException x)
+		{
+			LOG.debug("Exception while filling", x);
 			try
 			{
-				synchronized(bbuf)
-				{
-					try
-					{
-						bbuf.position(buffer.putIndex());
-						len = _channel.read(bbuf);
-					}
-					finally
-					{
-						buffer.setPutIndex(bbuf.position());
-						bbuf.position(0);
-					}
-				}
-
-				if (len<0 && isOpen())
-				{
-					if (!isInputShutdown())
-						shutdownInput();
-					if (isOutputShutdown())
-						_channel.close();
-				}
+				if (_channel.isOpen())
+					_channel.close();
 			}
-			catch (IOException x)
+			catch (Exception xx)
 			{
-				LOG.debug("Exception while filling", x);
-				try
-				{
-					if (_channel.isOpen())
-						_channel.close();
-				}
-				catch (Exception xx)
-				{
-					LOG.trace("",xx);
-				}
+				LOG.trace("",xx);
+			}
 
-				if (len>0)
-					throw x;
-				len = -1;
-			}
-		}
-		else
-		{
-			throw new IOException("Not Implemented");
+			if (len>0)
+				throw x;
+			len = -1;
 		}
 
 		return len;
 	}
 
 	@Override
-	public int flush(Buffer buffer) throws IOException
+	public int flush(JBuffer buffer) throws IOException
 	{
-		Buffer buf = buffer.buffer();
+		JBuffer nbuf = buffer.buffer();
 		int len=0;
-		if (buf instanceof NIOBuffer)
+		final ByteBuffer bbuf = nbuf.getByteBuffer().asReadOnlyBuffer();
+		try
 		{
-			final NIOBuffer nbuf = (NIOBuffer)buf;
-			final ByteBuffer bbuf = nbuf.getByteBuffer().asReadOnlyBuffer();
-			try
-			{
-				bbuf.position(buffer.getIndex());
-				bbuf.limit(buffer.putIndex());
-				len=_channel.write(bbuf);
-			}
-			finally
-			{
-				if (len>0)
-					buffer.skip(len);
-			}
+			bbuf.position(buffer.getIndex());
+			bbuf.limit(buffer.putIndex());
+			len=_channel.write(bbuf);
 		}
-		else if (buffer.array()!=null)
+		finally
 		{
-			ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.remaining());
-			len=_channel.write(b);
 			if (len>0)
 				buffer.skip(len);
 		}
-		else
-		{
-			throw new IOException("Not Implemented");
-		}
 		return len;
 	}
 
 	@Override
-	public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
+	public int flush(JBuffer header, JBuffer buffer, JBuffer trailer) throws IOException
 	{
 		int length=0;
 
-		Buffer buf0 = header==null?null:header.buffer();
-		Buffer buf1 = buffer==null?null:buffer.buffer();
+		JBuffer buf0 = header==null?null:header.buffer();
+		JBuffer buf1 = buffer==null?null:buffer.buffer();
 
 		if (_channel instanceof GatheringByteChannel &&
-			header!=null && header.remaining()!=0 && buf0 instanceof NIOBuffer &&
-			buffer!=null && buffer.remaining()!=0 && buf1 instanceof NIOBuffer)
+			header!=null && header.remaining()!=0 &&
+			buffer!=null && buffer.remaining()!=0)
 		{
-			length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer());
+			length = gatheringFlush(header,buf0.getByteBuffer(),buffer,buf1.getByteBuffer());
 		}
 		else
 		{
@@ -296,7 +273,7 @@
 		return length;
 	}
 
-	private int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
+	private int gatheringFlush(JBuffer header, ByteBuffer bbuf0, JBuffer buffer, ByteBuffer bbuf1) throws IOException
 	{
 		int length;