diff src/org/eclipse/jetty/http/HttpGenerator.java @ 1038:b71ad168fe34

rename Buffer.length() to remaining()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2016 22:16:11 -0600
parents b87f97f6418a
children a7319f14ba1e
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpGenerator.java	Thu Nov 03 21:54:34 2016 -0600
+++ b/src/org/eclipse/jetty/http/HttpGenerator.java	Thu Nov 03 22:16:11 2016 -0600
@@ -145,26 +145,26 @@
 		_last = last;
 
 		// Handle any unfinished business?
-		if (_content!=null && _content.length()>0 || _bufferChunked)
+		if (_content!=null && _content.remaining()>0 || _bufferChunked)
 		{
 			if (_endp.isOutputShutdown())
 				throw new EofException();
 			flushBuffer();
-			if (_content != null && _content.length()>0)
+			if (_content != null && _content.remaining()>0)
 			{
 				if (_bufferChunked)
 				{
-					Buffer nc = _buffers.getBuffer(_content.length()+CHUNK_SPACE+content.length());
+					Buffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining());
 					nc.put(_content);
 					nc.put(HttpTokens.CRLF);
-					BufferUtil.putHexInt(nc, content.length());
+					BufferUtil.putHexInt(nc, content.remaining());
 					nc.put(HttpTokens.CRLF);
 					nc.put(content);
 					content=nc;
 				}
 				else
 				{
-					Buffer nc = _buffers.getBuffer(_content.length()+content.length());
+					Buffer nc = _buffers.getBuffer(_content.remaining()+content.remaining());
 					nc.put(_content);
 					nc.put(content);
 					content=nc;
@@ -173,7 +173,7 @@
 		}
 
 		_content = content;
-		_contentWritten += content.length();
+		_contentWritten += content.remaining();
 
 		// Handle the _content
 		if (_head)
@@ -181,7 +181,7 @@
 			content.clear();
 			_content=null;
 		}
-		else if (_endp != null && (_buffer==null || _buffer.length()==0) && _content.length() > 0 && (_last || isCommitted() && _content.length()>1024))
+		else if (_endp != null && (_buffer==null || _buffer.remaining()==0) && _content.remaining() > 0 && (_last || isCommitted() && _content.remaining()>1024))
 		{
 			_bypass = true;
 		}
@@ -194,7 +194,7 @@
 			// Copy _content to buffer;
 			int len=_buffer.put(_content);
 			_content.skip(len);
-			if (_content.length() == 0)
+			if (_content.remaining() == 0)
 				_content = null;
 		}
 	}
@@ -215,10 +215,10 @@
 
 		// Handle any unfinished business?
 		Buffer content = _content;
-		if (content != null && content.length()>0 || _bufferChunked)
+		if (content != null && content.remaining()>0 || _bufferChunked)
 		{
 			flushBuffer();
-			if (content != null && content.length()>0 || _bufferChunked)
+			if (content != null && content.remaining()>0 || _bufferChunked)
 				throw new IllegalStateException("FULL");
 		}
 
@@ -226,7 +226,7 @@
 		if (_buffer == null)
 			_buffer = _buffers.getBuffer();
 
-		_contentWritten-=_buffer.length();
+		_contentWritten-=_buffer.remaining();
 
 		// Handle the _content
 		if (_head)
@@ -263,7 +263,7 @@
 		try
 		{
 			// nasty semi busy flush!
-			while(_header.length()>0)
+			while(_header.remaining()>0)
 			{
 				int len = _endp.flush(_header);
 				if (len<0)
@@ -793,7 +793,7 @@
 
 								// Special case handling for small left over buffer from
 								// an addContent that caused a buffer flush.
-								if (_content != null && _content.length() < _buffer.space() && _state != STATE_FLUSHING)
+								if (_content != null && _content.remaining() < _buffer.space() && _state != STATE_FLUSHING)
 								{
 									_buffer.put(_content);
 									_content.clear();
@@ -803,7 +803,7 @@
 						}
 
 						// Are we completely finished for now?
-						if (!_needCRLF && !_needEOC && (_content==null || _content.length()==0))
+						if (!_needCRLF && !_needEOC && (_content==null || _content.remaining()==0))
 						{
 							if (_state == STATE_FLUSHING)
 								_state = STATE_END;
@@ -837,9 +837,9 @@
 
 	private int flushMask()
 	{
-		return  ((_header != null && _header.length() > 0)?4:0)
-		| ((_buffer != null && _buffer.length() > 0)?2:0)
-		| ((_bypass && _content != null && _content.length() > 0)?1:0);
+		return  ((_header != null && _header.remaining() > 0)?4:0)
+		| ((_buffer != null && _buffer.remaining() > 0)?2:0)
+		| ((_bypass && _content != null && _content.remaining() > 0)?1:0);
 	}
 
 	private void prepareBuffers()
@@ -848,21 +848,21 @@
 		if (!_bufferChunked)
 		{
 			// Refill buffer if possible
-			if (!_bypass && _content != null && _content.length() > 0 && _buffer != null && _buffer.space() > 0)
+			if (!_bypass && _content != null && _content.remaining() > 0 && _buffer != null && _buffer.space() > 0)
 			{
 				int len = _buffer.put(_content);
 				_content.skip(len);
-				if (_content.length() == 0)
+				if (_content.remaining() == 0)
 					_content = null;
 			}
 
 			// Chunk buffer if need be
 			if (_contentLength == HttpTokens.CHUNKED_CONTENT)
 			{
-				if (_bypass && (_buffer==null||_buffer.length()==0) && _content!=null)
+				if (_bypass && (_buffer==null||_buffer.remaining()==0) && _content!=null)
 				{
 					// this is a bypass write
-					int size = _content.length();
+					int size = _content.remaining();
 					_bufferChunked = true;
 
 					if (_header == null)
@@ -871,7 +871,7 @@
 					// if we need CRLF add this to header
 					if (_needCRLF)
 					{
-						if (_header.length() > 0) throw new IllegalStateException("EOC");
+						if (_header.remaining() > 0) throw new IllegalStateException("EOC");
 						_header.put(HttpTokens.CRLF);
 						_needCRLF = false;
 					}
@@ -884,7 +884,7 @@
 				}
 				else if (_buffer!=null)
 				{
-					int size = _buffer.length();
+					int size = _buffer.remaining();
 					if (size > 0)
 					{
 						// Prepare a chunk!
@@ -914,7 +914,7 @@
 
 							if (_needCRLF)
 							{
-								if (_header.length() > 0) throw new IllegalStateException("EOC");
+								if (_header.remaining() > 0) throw new IllegalStateException("EOC");
 								_header.put(HttpTokens.CRLF);
 								_needCRLF = false;
 							}
@@ -931,7 +931,7 @@
 				}
 
 				// If we need EOC and everything written
-				if (_needEOC && (_content == null || _content.length() == 0))
+				if (_needEOC && (_content == null || _content.remaining() == 0))
 				{
 					if (_header == null && _buffer == null)
 						_header = _buffers.getHeader();
@@ -975,7 +975,7 @@
 			}
 		}
 
-		if (_content != null && _content.length() == 0)
+		if (_content != null && _content.remaining() == 0)
 			_content = null;
 
 	}
@@ -989,8 +989,8 @@
 		return String.format("%s{s=%d,h=%d,b=%d,c=%d}",
 				getClass().getSimpleName(),
 				_state,
-				header == null ? -1 : header.length(),
-				buffer == null ? -1 : buffer.length(),
-				content == null ? -1 : content.length());
+				header == null ? -1 : header.remaining(),
+				buffer == null ? -1 : buffer.remaining(),
+				content == null ? -1 : content.remaining());
 	}
 }