changeset 1041:35e3c864d7a7

make View package local
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 00:47:23 -0600
parents 3e4949834f3e
children a62193321d6a
files src/org/eclipse/jetty/http/HttpParser.java src/org/eclipse/jetty/io/AbstractBuffer.java src/org/eclipse/jetty/io/Buffer.java src/org/eclipse/jetty/io/View.java
diffstat 4 files changed, 28 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpParser.java	Thu Nov 03 23:04:11 2016 -0600
+++ b/src/org/eclipse/jetty/http/HttpParser.java	Fri Nov 04 00:47:23 2016 -0600
@@ -21,10 +21,10 @@
 import java.io.IOException;
 
 import org.eclipse.jetty.io.Buffer;
+import org.eclipse.jetty.io.ByteArrayBuffer;
 import org.eclipse.jetty.io.BufferUtil;
 import org.eclipse.jetty.io.EndPoint;
 import org.eclipse.jetty.io.EofException;
-import org.eclipse.jetty.io.View;
 import org.eclipse.jetty.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,7 +67,7 @@
 	private int _responseStatus; // If >0 then we are parsing a response
 	private boolean _persistent;
 
-	private final View  _contentView = new View(); // View of the content in the buffer for {@link Input}
+	private Buffer _contentView = new ByteArrayBuffer(0); // View of the content in the buffer for {@link Input}
 	private int _state = STATE_START;
 	private byte _eol;
 	private int _length;
@@ -208,7 +208,7 @@
 						{
 							Buffer chunk = _buffer.get(_buffer.remaining());
 							_contentPosition += chunk.remaining();
-							_contentView.update(chunk);
+							_contentView = chunk;
 							_handler.content(); // May recurse here
 						}
 					}
@@ -733,7 +733,6 @@
 
 			// Handle _content
 			length=_buffer.remaining();
-			Buffer chunk;
 			last=_state;
 			while (_state > STATE_END && length > 0)
 			{
@@ -753,12 +752,14 @@
 				switch (_state)
 				{
 					case STATE_EOF_CONTENT:
-						chunk=_buffer.get(_buffer.remaining());
+					{
+						Buffer chunk = _buffer.get(_buffer.remaining());
 						_contentPosition += chunk.remaining();
-						_contentView.update(chunk);
+						_contentView = chunk;
 						_handler.content(); // May recurse here
 						// TODO adjust the _buffer to keep unconsumed content
 						return 1;
+					}
 
 					case STATE_CONTENT:
 					{
@@ -777,9 +778,9 @@
 							length=(int)remaining;
 						}
 
-						chunk=_buffer.get(length);
+						Buffer chunk = _buffer.get(length);
 						_contentPosition += chunk.remaining();
-						_contentView.update(chunk);
+						_contentView = chunk;
 						_handler.content(); // May recurse here
 
 						if(_contentPosition == _contentLength)
@@ -868,10 +869,10 @@
 						}
 						else if (length > remaining)
 							length=remaining;
-						chunk=_buffer.get(length);
+						Buffer chunk = _buffer.get(length);
 						_contentPosition += chunk.remaining();
 						_chunkPosition += chunk.remaining();
-						_contentView.update(chunk);
+						_contentView = chunk;
 						_handler.content(); // May recurse here
 						// TODO adjust the _buffer to keep unconsumed content
 						return 1;
@@ -1022,7 +1023,7 @@
 	 */
 	public int available() throws IOException
 	{
-		if (_contentView!=null && _contentView.remaining()>0)
+		if (_contentView.remaining()>0)
 			return _contentView.remaining();
 
 		if (_endp.isBlocking())
@@ -1031,7 +1032,7 @@
 		}
 
 		parseNext();
-		return _contentView==null?0:_contentView.remaining();
+		return _contentView.remaining();
 	}
 
 
--- a/src/org/eclipse/jetty/io/AbstractBuffer.java	Thu Nov 03 23:04:11 2016 -0600
+++ b/src/org/eclipse/jetty/io/AbstractBuffer.java	Fri Nov 04 00:47:23 2016 -0600
@@ -47,7 +47,6 @@
 	protected int _hashGet;
 	protected int _hashPut;
 	protected int _mark;
-	protected View _view;
 
 	/**
 	 * Constructor for BufferView
@@ -243,20 +242,10 @@
 
 	private Buffer peek(int index, int length)
 	{
-		if (_view == null)
-		{
-			_view = new View(this, -1, index, index + length, isReadOnly() ? READONLY : READWRITE);
-		}
-		else
-		{
-			_view.update(this.buffer());
-			_view.setMarkIndex(-1);
-			_view.setGetIndex(0);
-			_view.setPutIndex(index + length);
-			_view.setGetIndex(index);
-			
-		}
-		return _view;
+		Buffer view = duplicate();
+		view.setPutIndex(index + length);
+		view.setGetIndex(index);
+		return view;
 	}
 
 	@Override
@@ -544,4 +533,8 @@
 			return total; 
 		}
 	}
+
+	public final Buffer duplicate() {
+		return new View(this);
+	}
 }
--- a/src/org/eclipse/jetty/io/Buffer.java	Thu Nov 03 23:04:11 2016 -0600
+++ b/src/org/eclipse/jetty/io/Buffer.java	Fri Nov 04 00:47:23 2016 -0600
@@ -300,4 +300,7 @@
 	
 	String toString(Charset charset);
 
+
+	// like ByteBuffer
+	Buffer duplicate();
 }
--- a/src/org/eclipse/jetty/io/View.java	Thu Nov 03 23:04:11 2016 -0600
+++ b/src/org/eclipse/jetty/io/View.java	Fri Nov 04 00:47:23 2016 -0600
@@ -25,45 +25,21 @@
  * 
  * 
  */
-public final class View extends AbstractBuffer
+final class View extends AbstractBuffer
 {
 	private Buffer _buffer;
 
-	/**
-	 * @param buffer The <code>Buffer</code> on which we are presenting a <code>View</code>.
-	 * @param mark The initial value of the {@link Buffer#markIndex mark index}
-	 * @param get The initial value of the {@link Buffer#getIndex get index}
-	 * @param put The initial value of the {@link Buffer#putIndex put index}
-	 * @param access The access level - one of the constants from {@link Buffer}.
-	 */
-	public View(Buffer buffer, int mark, int get, int put,int access)
+	View(Buffer buffer)
 	{
-		super(access);
-		_buffer = buffer.buffer();
-		setPutIndex(put);
-		setGetIndex(get);
-		setMarkIndex(mark);
-	}
-	
-	public View()
-	{
-		super(READWRITE);
-	}
-	
-	/**
-	 * Update view to buffer
-	 */
-	public void update(Buffer buffer)
-	{
-		_access = READWRITE;
+		super( buffer.isReadOnly()?READONLY:READWRITE );
 		_buffer = buffer.buffer();
 		setGetIndex(0);
 		setPutIndex(buffer.putIndex());
 		setGetIndex(buffer.getIndex());
 		setMarkIndex(buffer.markIndex());
-		_access = buffer.isReadOnly()?READONLY:READWRITE;
 	}
 
+
 	@Override
 	public byte[] array()
 	{