comparison src/org/eclipse/jetty/http/HttpParser.java @ 1048:2b769da7f67d

remove Buffer
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 07 Nov 2016 23:15:42 -0700
parents a8c92b0a08ed
children 5ef954fad97b
comparison
equal deleted inserted replaced
1047:1accf965d51a 1048:2b769da7f67d
18 18
19 package org.eclipse.jetty.http; 19 package org.eclipse.jetty.http;
20 20
21 import java.io.IOException; 21 import java.io.IOException;
22 22
23 import org.eclipse.jetty.io.Buffer; 23 import org.eclipse.jetty.io.JBuffer;
24 import org.eclipse.jetty.io.BufferUtil; 24 import org.eclipse.jetty.io.BufferUtil;
25 import org.eclipse.jetty.io.EndPoint; 25 import org.eclipse.jetty.io.EndPoint;
26 import org.eclipse.jetty.io.EofException; 26 import org.eclipse.jetty.io.EofException;
27 import org.eclipse.jetty.util.StringUtil; 27 import org.eclipse.jetty.util.StringUtil;
28 import org.slf4j.Logger; 28 import org.slf4j.Logger;
54 private static final int STATE_CHUNK = 6; 54 private static final int STATE_CHUNK = 6;
55 private static final int STATE_SEEKING_EOF = 7; 55 private static final int STATE_SEEKING_EOF = 7;
56 56
57 private final EventHandler _handler; 57 private final EventHandler _handler;
58 private final EndPoint _endp; 58 private final EndPoint _endp;
59 public final Buffer _header; // Buffer for header data (and small _content) 59 public final JBuffer _header; // JBuffer for header data (and small _content)
60 private final Buffer _body; // Buffer for large content 60 private final JBuffer _body; // JBuffer for large content
61 private Buffer _buffer; // The current buffer in use (either _header or _content) 61 private JBuffer _buffer; // The current buffer in use (either _header or _content)
62 private int _mark = -1; 62 private int _mark = -1;
63 private String _cached; 63 private String _cached;
64 private String _tok0 = ""; // Saved token: header name, request method or response version 64 private String _tok0 = ""; // Saved token: header name, request method or response version
65 private String _tok1 = ""; // Saved token: header value, request URI or response code 65 private String _tok1 = ""; // Saved token: header value, request URI or response code
66 private String _multiLineValue; 66 private String _multiLineValue;
67 private int _responseStatus; // If >0 then we are parsing a response 67 private int _responseStatus; // If >0 then we are parsing a response
68 private boolean _persistent; 68 private boolean _persistent;
69 69
70 private Buffer _contentView = BufferUtil.EMPTY_BUFFER; // View of the content in the buffer for {@link Input} 70 private JBuffer _contentView = BufferUtil.EMPTY_BUFFER; // View of the content in the buffer for {@link Input}
71 private int _state = STATE_START; 71 private int _state = STATE_START;
72 private byte _eol; 72 private byte _eol;
73 private int _length; 73 private int _length;
74 private long _contentLength; 74 private long _contentLength;
75 private long _contentPosition; 75 private long _contentPosition;
76 private int _chunkLength; 76 private int _chunkLength;
77 private int _chunkPosition; 77 private int _chunkPosition;
78 private boolean _headResponse; 78 private boolean _headResponse;
79 79
80 public HttpParser(Buffer headerBuffer,Buffer bodyBuffer, EndPoint endp, EventHandler handler) 80 public HttpParser(JBuffer headerBuffer,JBuffer bodyBuffer, EndPoint endp, EventHandler handler)
81 { 81 {
82 _header = headerBuffer; 82 _header = headerBuffer;
83 _body = bodyBuffer; 83 _body = bodyBuffer;
84 _endp = endp; 84 _endp = endp;
85 _handler = handler; 85 _handler = handler;
87 87
88 private void mark() { 88 private void mark() {
89 _mark = _buffer.getIndex() - 1; 89 _mark = _buffer.getIndex() - 1;
90 } 90 }
91 91
92 private Buffer sliceFromMark() { 92 private JBuffer sliceFromMark() {
93 Buffer buf = _buffer.sliceFrom(_mark); 93 JBuffer buf = _buffer.sliceFrom(_mark);
94 _mark = -1; 94 _mark = -1;
95 return buf; 95 return buf;
96 } 96 }
97 97
98 private void clear() { 98 private void clear() {
232 // do we have content to deliver? 232 // do we have content to deliver?
233 if (_state>STATE_END) 233 if (_state>STATE_END)
234 { 234 {
235 if (_buffer.remaining()>0 && !_headResponse) 235 if (_buffer.remaining()>0 && !_headResponse)
236 { 236 {
237 Buffer chunk = _buffer.get(_buffer.remaining()); 237 JBuffer chunk = _buffer.get(_buffer.remaining());
238 _contentPosition += chunk.remaining(); 238 _contentPosition += chunk.remaining();
239 _contentView = chunk; 239 _contentView = chunk;
240 _handler.content(); // May recurse here 240 _handler.content(); // May recurse here
241 } 241 }
242 } 242 }
779 _eol=0; 779 _eol=0;
780 switch (_state) 780 switch (_state)
781 { 781 {
782 case STATE_EOF_CONTENT: 782 case STATE_EOF_CONTENT:
783 { 783 {
784 Buffer chunk = _buffer.get(_buffer.remaining()); 784 JBuffer chunk = _buffer.get(_buffer.remaining());
785 _contentPosition += chunk.remaining(); 785 _contentPosition += chunk.remaining();
786 _contentView = chunk; 786 _contentView = chunk;
787 _handler.content(); // May recurse here 787 _handler.content(); // May recurse here
788 // TODO adjust the _buffer to keep unconsumed content 788 // TODO adjust the _buffer to keep unconsumed content
789 return 1; 789 return 1;
804 // We can cast reamining to an int as we know that it is smaller than 804 // We can cast reamining to an int as we know that it is smaller than
805 // or equal to length which is already an int. 805 // or equal to length which is already an int.
806 length=(int)remaining; 806 length=(int)remaining;
807 } 807 }
808 808
809 Buffer chunk = _buffer.get(length); 809 JBuffer chunk = _buffer.get(length);
810 _contentPosition += chunk.remaining(); 810 _contentPosition += chunk.remaining();
811 _contentView = chunk; 811 _contentView = chunk;
812 _handler.content(); // May recurse here 812 _handler.content(); // May recurse here
813 813
814 if(_contentPosition == _contentLength) 814 if(_contentPosition == _contentLength)
895 _state=STATE_CHUNKED_CONTENT; 895 _state=STATE_CHUNKED_CONTENT;
896 break; 896 break;
897 } 897 }
898 else if (length > remaining) 898 else if (length > remaining)
899 length=remaining; 899 length=remaining;
900 Buffer chunk = _buffer.get(length); 900 JBuffer chunk = _buffer.get(length);
901 _contentPosition += chunk.remaining(); 901 _contentPosition += chunk.remaining();
902 _chunkPosition += chunk.remaining(); 902 _chunkPosition += chunk.remaining();
903 _contentView = chunk; 903 _contentView = chunk;
904 _handler.content(); // May recurse here 904 _handler.content(); // May recurse here
905 // TODO adjust the _buffer to keep unconsumed content 905 // TODO adjust the _buffer to keep unconsumed content
1003 _state, 1003 _state,
1004 _length, 1004 _length,
1005 _contentLength); 1005 _contentLength);
1006 } 1006 }
1007 1007
1008 public Buffer blockForContent(long maxIdleTime) throws IOException 1008 public JBuffer blockForContent(long maxIdleTime) throws IOException
1009 { 1009 {
1010 if (_contentView.remaining()>0) 1010 if (_contentView.remaining()>0)
1011 return _contentView; 1011 return _contentView;
1012 1012
1013 if (_state <= STATE_END || _state==STATE_SEEKING_EOF) 1013 if (_state <= STATE_END || _state==STATE_SEEKING_EOF)