diff src/org/eclipse/jetty/http/HttpParser.java @ 1054:87275900646e

remove JBuffer.toString()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2016 01:03:02 -0700
parents 7e4b41247544
children 013939bfc9e8
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpParser.java	Tue Nov 08 00:32:02 2016 -0700
+++ b/src/org/eclipse/jetty/http/HttpParser.java	Tue Nov 08 01:03:02 2016 -0700
@@ -89,12 +89,12 @@
 		_mark = _buffer.getIndex() - 1;
 	}
 
-	private JBuffer sliceFromMark() {
+	private String sliceFromMark() {
 		JBuffer buf = _buffer.duplicate();
 		buf.position(_mark);
 		buf.limit(_buffer.position()-1);
 		_mark = -1;
-		return buf;
+		return BufferUtil.getString(buf);
 	}
 
 	private void clear() {
@@ -114,7 +114,7 @@
 		}
 	}
 
-	public JBuffer getBuffer(int length) {
+	private JBuffer getBuffer(int length) {
 		JBuffer dup = _buffer.duplicate();
 		int end = _buffer.position() + length;
 		dup.limit(end);
@@ -122,10 +122,17 @@
 		return dup;
 	}
 
-	public byte peek() {
+	private byte peek() {
 		return _buffer.get(_buffer.position());
 	}
 
+	private String bufferToString(int index, int length) {
+		JBuffer dup = _buffer.duplicate();
+		dup.limit(index+length);
+		dup.position(index);
+		return BufferUtil.getString(dup);
+	}
+
 
 	public long getContentLength()
 	{
@@ -328,7 +335,7 @@
 					case STATE_FIELD0:
 						if (ch == HttpTokens.SPACE)
 						{
-							_tok0 = _buffer.toString(_mark, _buffer.getIndex() - 1 - _mark);
+							_tok0 = bufferToString(_mark, _buffer.getIndex() - 1 - _mark);
 							_responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0;
 							_state=STATE_SPACE1;
 							continue;
@@ -361,7 +368,7 @@
 						if (ch == HttpTokens.SPACE)
 						{
 //							_tok1.update(_mark, _buffer.getIndex() - 1);
-							_tok1 = _buffer.toString(_mark, _buffer.getIndex() - 1 - _mark);
+							_tok1 = bufferToString(_mark, _buffer.getIndex() - 1 - _mark);
 							_state = STATE_SPACE2;
 							continue;
 						}
@@ -388,14 +395,14 @@
 						if (ch == HttpTokens.SPACE)
 						{
 //							_tok1.update(_mark, _buffer.getIndex() - 1);
-							_tok1 = _buffer.toString(_mark, _buffer.getIndex() - 1 - _mark);
+							_tok1 = bufferToString(_mark, _buffer.getIndex() - 1 - _mark);
 							_state=STATE_SPACE2;
 							continue;
 						}
 						else if (ch < HttpTokens.SPACE && ch>=0)
 						{
 							// HTTP/0.9
-							_handler.startRequest(_tok0, sliceFromMark().toString(), null);
+							_handler.startRequest(_tok0, sliceFromMark(), null);
 							_persistent = false;
 							_state = STATE_SEEKING_EOF;
 							_handler.headerComplete();
@@ -441,7 +448,7 @@
 //								_handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,sliceFromMark());
 								version = _tok0;
 							else
-								_handler.startRequest(_tok0, _tok1, version=sliceFromMark().toString());
+								_handler.startRequest(_tok0, _tok1, version=sliceFromMark());
 							_eol=ch;
 							_persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL;
 							_state=STATE_HEADER;
@@ -637,14 +644,14 @@
 							case HttpTokens.CARRIAGE_RETURN:
 							case HttpTokens.LINE_FEED:
 								if (_length > 0) {
-									_tok0 = _buffer.toString(_mark, _length);
+									_tok0 = bufferToString(_mark, _length);
 								}
 								_eol=ch;
 								_state=STATE_HEADER;
 								break;
 							case HttpTokens.COLON:
 								if (_length > 0 && _cached==null) {
-									_tok0 = _buffer.toString(_mark, _length);
+									_tok0 = bufferToString(_mark, _length);
 								}
 								_length=-1;
 								_state=STATE_HEADER_VALUE;
@@ -670,14 +677,14 @@
 							case HttpTokens.CARRIAGE_RETURN:
 							case HttpTokens.LINE_FEED:
 								if (_length > 0) {
-									_tok0 = _buffer.toString(_mark,_length);
+									_tok0 = bufferToString(_mark,_length);
 								}
 								_eol=ch;
 								_state=STATE_HEADER;
 								break;
 							case HttpTokens.COLON:
 								if (_length > 0 && _cached==null) {
-									_tok0 = _buffer.toString(_mark,_length);
+									_tok0 = bufferToString(_mark,_length);
 								}
 								_length=-1;
 								_state=STATE_HEADER_VALUE;
@@ -703,13 +710,13 @@
 								{
 									if (_tok1.length() == 0)
 //										_tok1.update(_mark, _mark + _length);
-										_tok1 = _buffer.toString(_mark, _length);
+										_tok1 = bufferToString(_mark, _length);
 									else
 									{
 										// Continuation line!
 										if (_multiLineValue == null) _multiLineValue = _tok1;
 //										_tok1.update(_mark, _mark + _length);
-										_tok1 = _buffer.toString(_mark, _length);
+										_tok1 = bufferToString(_mark, _length);
 										_multiLineValue += " " + _tok1;
 									}
 								}
@@ -738,13 +745,13 @@
 								{
 									if (_tok1.length() == 0)
 //										_tok1.update(_mark, _mark + _length);
-										_tok1 = _buffer.toString(_mark, _length);
+										_tok1 = bufferToString(_mark, _length);
 									else
 									{
 										// Continuation line!
 										if (_multiLineValue == null) _multiLineValue = _tok1;
 //										_tok1.update(_mark, _mark + _length);
-										_tok1 = _buffer.toString(_mark, _length);
+										_tok1 = bufferToString(_mark, _length);
 										_multiLineValue += " " + _tok1;
 									}
 								}