comparison src/org/eclipse/jetty/http/HttpParser.java @ 1038:b71ad168fe34

rename Buffer.length() to remaining()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2016 22:16:11 -0600
parents 3c4c7cc7904f
children 35e3c864d7a7
comparison
equal deleted inserted replaced
1037:3c4c7cc7904f 1038:b71ad168fe34
142 public boolean parseAvailable() throws IOException 142 public boolean parseAvailable() throws IOException
143 { 143 {
144 boolean progress = parseNext() > 0; 144 boolean progress = parseNext() > 0;
145 145
146 // continue parsing 146 // continue parsing
147 while (!isComplete() && _buffer!=null && _buffer.length()>0 && !_contentView.hasRemaining()) 147 while (!isComplete() && _buffer!=null && _buffer.remaining()>0 && !_contentView.hasRemaining())
148 { 148 {
149 progress |= parseNext()>0; 149 progress |= parseNext()>0;
150 } 150 }
151 return progress; 151 return progress;
152 } 152 }
175 _state=STATE_END; 175 _state=STATE_END;
176 _handler.messageComplete(_contentPosition); 176 _handler.messageComplete(_contentPosition);
177 return 1; 177 return 1;
178 } 178 }
179 179
180 int length = _buffer.length(); 180 int length = _buffer.remaining();
181 181
182 // Fill buffer if we can 182 // Fill buffer if we can
183 if (length == 0) 183 if (length == 0)
184 { 184 {
185 int filled=-1; 185 int filled=-1;
186 IOException ex=null; 186 IOException ex=null;
187 try 187 try
188 { 188 {
189 filled=fill(); 189 filled=fill();
190 LOG.debug("filled {}/{}",filled,_buffer.length()); 190 LOG.debug("filled {}/{}",filled,_buffer.remaining());
191 } 191 }
192 catch(IOException e) 192 catch(IOException e)
193 { 193 {
194 LOG.debug(this.toString(),e); 194 LOG.debug(this.toString(),e);
195 ex=e; 195 ex=e;
202 _persistent = false; 202 _persistent = false;
203 203
204 // do we have content to deliver? 204 // do we have content to deliver?
205 if (_state>STATE_END) 205 if (_state>STATE_END)
206 { 206 {
207 if (_buffer.length()>0 && !_headResponse) 207 if (_buffer.remaining()>0 && !_headResponse)
208 { 208 {
209 Buffer chunk = _buffer.get(_buffer.length()); 209 Buffer chunk = _buffer.get(_buffer.remaining());
210 _contentPosition += chunk.length(); 210 _contentPosition += chunk.remaining();
211 _contentView.update(chunk); 211 _contentView.update(chunk);
212 _handler.content(); // May recurse here 212 _handler.content(); // May recurse here
213 } 213 }
214 } 214 }
215 215
239 if (!isComplete() && !isIdle()) 239 if (!isComplete() && !isIdle())
240 throw new EofException(); 240 throw new EofException();
241 241
242 return -1; 242 return -1;
243 } 243 }
244 length=_buffer.length(); 244 length=_buffer.remaining();
245 } 245 }
246 246
247 247
248 // Handle header states 248 // Handle header states
249 byte ch; 249 byte ch;
577 577
578 if (_cached!=null) 578 if (_cached!=null)
579 { 579 {
580 _length = _cached.length(); 580 _length = _cached.length();
581 _buffer.setGetIndex(_buffer.markIndex()+_length); 581 _buffer.setGetIndex(_buffer.markIndex()+_length);
582 length = _buffer.length(); 582 length = _buffer.remaining();
583 } 583 }
584 } 584 }
585 } 585 }
586 } 586 }
587 } 587 }
730 730
731 731
732 // ========================== 732 // ==========================
733 733
734 // Handle _content 734 // Handle _content
735 length=_buffer.length(); 735 length=_buffer.remaining();
736 Buffer chunk; 736 Buffer chunk;
737 last=_state; 737 last=_state;
738 while (_state > STATE_END && length > 0) 738 while (_state > STATE_END && length > 0)
739 { 739 {
740 if (last!=_state) 740 if (last!=_state)
744 } 744 }
745 745
746 if (_eol == HttpTokens.CARRIAGE_RETURN && _buffer.peek() == HttpTokens.LINE_FEED) 746 if (_eol == HttpTokens.CARRIAGE_RETURN && _buffer.peek() == HttpTokens.LINE_FEED)
747 { 747 {
748 _eol=_buffer.get(); 748 _eol=_buffer.get();
749 length=_buffer.length(); 749 length=_buffer.remaining();
750 continue; 750 continue;
751 } 751 }
752 _eol=0; 752 _eol=0;
753 switch (_state) 753 switch (_state)
754 { 754 {
755 case STATE_EOF_CONTENT: 755 case STATE_EOF_CONTENT:
756 chunk=_buffer.get(_buffer.length()); 756 chunk=_buffer.get(_buffer.remaining());
757 _contentPosition += chunk.length(); 757 _contentPosition += chunk.remaining();
758 _contentView.update(chunk); 758 _contentView.update(chunk);
759 _handler.content(); // May recurse here 759 _handler.content(); // May recurse here
760 // TODO adjust the _buffer to keep unconsumed content 760 // TODO adjust the _buffer to keep unconsumed content
761 return 1; 761 return 1;
762 762
776 // or equal to length which is already an int. 776 // or equal to length which is already an int.
777 length=(int)remaining; 777 length=(int)remaining;
778 } 778 }
779 779
780 chunk=_buffer.get(length); 780 chunk=_buffer.get(length);
781 _contentPosition += chunk.length(); 781 _contentPosition += chunk.remaining();
782 _contentView.update(chunk); 782 _contentView.update(chunk);
783 _handler.content(); // May recurse here 783 _handler.content(); // May recurse here
784 784
785 if(_contentPosition == _contentLength) 785 if(_contentPosition == _contentLength)
786 { 786 {
867 break; 867 break;
868 } 868 }
869 else if (length > remaining) 869 else if (length > remaining)
870 length=remaining; 870 length=remaining;
871 chunk=_buffer.get(length); 871 chunk=_buffer.get(length);
872 _contentPosition += chunk.length(); 872 _contentPosition += chunk.remaining();
873 _chunkPosition += chunk.length(); 873 _chunkPosition += chunk.remaining();
874 _contentView.update(chunk); 874 _contentView.update(chunk);
875 _handler.content(); // May recurse here 875 _handler.content(); // May recurse here
876 // TODO adjust the _buffer to keep unconsumed content 876 // TODO adjust the _buffer to keep unconsumed content
877 return 1; 877 return 1;
878 } 878 }
879 879
880 case STATE_SEEKING_EOF: 880 case STATE_SEEKING_EOF:
881 { 881 {
882 // Close if there is more data than CRLF 882 // Close if there is more data than CRLF
883 if (_buffer.length()>2) 883 if (_buffer.remaining()>2)
884 { 884 {
885 _state = STATE_END; 885 _state = STATE_END;
886 _endp.close(); 886 _endp.close();
887 } 887 }
888 else 888 else
889 { 889 {
890 // or if the data is not white space 890 // or if the data is not white space
891 while (_buffer.length()>0) 891 while (_buffer.remaining()>0)
892 if (!Character.isWhitespace(_buffer.get())) 892 if (!Character.isWhitespace(_buffer.get()))
893 { 893 {
894 _state = STATE_END; 894 _state = STATE_END;
895 _endp.close(); 895 _endp.close();
896 _buffer.clear(); 896 _buffer.clear();
900 _buffer.clear(); 900 _buffer.clear();
901 break; 901 break;
902 } 902 }
903 } 903 }
904 904
905 length=_buffer.length(); 905 length=_buffer.remaining();
906 } 906 }
907 907
908 return progress; 908 return progress;
909 } 909 }
910 catch(HttpException e) 910 catch(HttpException e)
927 927
928 // Is there unconsumed content in body buffer 928 // Is there unconsumed content in body buffer
929 if (_state>STATE_END && _buffer==_header && !_header.hasRemaining() && _body.hasRemaining()) 929 if (_state>STATE_END && _buffer==_header && !_header.hasRemaining() && _body.hasRemaining())
930 { 930 {
931 _buffer = _body; 931 _buffer = _body;
932 return _buffer.length(); 932 return _buffer.remaining();
933 } 933 }
934 934
935 // Shall we switch to a body buffer? 935 // Shall we switch to a body buffer?
936 if (_buffer==_header && _state>STATE_END && _header.length()==0 && ((_contentLength-_contentPosition)>_header.capacity())) 936 if (_buffer==_header && _state>STATE_END && _header.remaining()==0 && ((_contentLength-_contentPosition)>_header.capacity()))
937 { 937 {
938 _buffer = _body; 938 _buffer = _body;
939 } 939 }
940 940
941 // Shall we compact the body? 941 // Shall we compact the body?
976 _contentLength); 976 _contentLength);
977 } 977 }
978 978
979 public Buffer blockForContent(long maxIdleTime) throws IOException 979 public Buffer blockForContent(long maxIdleTime) throws IOException
980 { 980 {
981 if (_contentView.length()>0) 981 if (_contentView.remaining()>0)
982 return _contentView; 982 return _contentView;
983 983
984 if (_state <= STATE_END || _state==STATE_SEEKING_EOF) 984 if (_state <= STATE_END || _state==STATE_SEEKING_EOF)
985 return null; 985 return null;
986 986
987 try 987 try
988 { 988 {
989 parseNext(); 989 parseNext();
990 990
991 // parse until some progress is made (or IOException thrown for timeout) 991 // parse until some progress is made (or IOException thrown for timeout)
992 while(_contentView.length() == 0 && !(_state==STATE_END||_state==STATE_SEEKING_EOF) && _endp.isOpen()) 992 while(_contentView.remaining() == 0 && !(_state==STATE_END||_state==STATE_SEEKING_EOF) && _endp.isOpen())
993 { 993 {
994 if (!_endp.isBlocking()) 994 if (!_endp.isBlocking())
995 { 995 {
996 if (parseNext()>0) 996 if (parseNext()>0)
997 continue; 997 continue;
1011 // TODO is this needed? 1011 // TODO is this needed?
1012 _endp.close(); 1012 _endp.close();
1013 throw e; 1013 throw e;
1014 } 1014 }
1015 1015
1016 return _contentView.length()>0 ? _contentView : null; 1016 return _contentView.remaining()>0 ? _contentView : null;
1017 } 1017 }
1018 1018
1019 /* ------------------------------------------------------------ */ 1019 /* ------------------------------------------------------------ */
1020 /* (non-Javadoc) 1020 /* (non-Javadoc)
1021 * @see java.io.InputStream#available() 1021 * @see java.io.InputStream#available()
1022 */ 1022 */
1023 public int available() throws IOException 1023 public int available() throws IOException
1024 { 1024 {
1025 if (_contentView!=null && _contentView.length()>0) 1025 if (_contentView!=null && _contentView.remaining()>0)
1026 return _contentView.length(); 1026 return _contentView.remaining();
1027 1027
1028 if (_endp.isBlocking()) 1028 if (_endp.isBlocking())
1029 { 1029 {
1030 return 0; 1030 return 0;
1031 } 1031 }
1032 1032
1033 parseNext(); 1033 parseNext();
1034 return _contentView==null?0:_contentView.length(); 1034 return _contentView==null?0:_contentView.remaining();
1035 } 1035 }
1036 1036
1037 1037
1038 public interface EventHandler 1038 public interface EventHandler
1039 { 1039 {