comparison 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
comparison
equal deleted inserted replaced
1053:7e4b41247544 1054:87275900646e
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 JBuffer sliceFromMark() { 92 private String sliceFromMark() {
93 JBuffer buf = _buffer.duplicate(); 93 JBuffer buf = _buffer.duplicate();
94 buf.position(_mark); 94 buf.position(_mark);
95 buf.limit(_buffer.position()-1); 95 buf.limit(_buffer.position()-1);
96 _mark = -1; 96 _mark = -1;
97 return buf; 97 return BufferUtil.getString(buf);
98 } 98 }
99 99
100 private void clear() { 100 private void clear() {
101 _buffer.clear(); 101 _buffer.clear();
102 _mark = -1; 102 _mark = -1;
112 _buffer.setGetIndex( old - _mark ); 112 _buffer.setGetIndex( old - _mark );
113 _mark = 0; 113 _mark = 0;
114 } 114 }
115 } 115 }
116 116
117 public JBuffer getBuffer(int length) { 117 private JBuffer getBuffer(int length) {
118 JBuffer dup = _buffer.duplicate(); 118 JBuffer dup = _buffer.duplicate();
119 int end = _buffer.position() + length; 119 int end = _buffer.position() + length;
120 dup.limit(end); 120 dup.limit(end);
121 _buffer.position(end); 121 _buffer.position(end);
122 return dup; 122 return dup;
123 } 123 }
124 124
125 public byte peek() { 125 private byte peek() {
126 return _buffer.get(_buffer.position()); 126 return _buffer.get(_buffer.position());
127 }
128
129 private String bufferToString(int index, int length) {
130 JBuffer dup = _buffer.duplicate();
131 dup.limit(index+length);
132 dup.position(index);
133 return BufferUtil.getString(dup);
127 } 134 }
128 135
129 136
130 public long getContentLength() 137 public long getContentLength()
131 { 138 {
326 break; 333 break;
327 334
328 case STATE_FIELD0: 335 case STATE_FIELD0:
329 if (ch == HttpTokens.SPACE) 336 if (ch == HttpTokens.SPACE)
330 { 337 {
331 _tok0 = _buffer.toString(_mark, _buffer.getIndex() - 1 - _mark); 338 _tok0 = bufferToString(_mark, _buffer.getIndex() - 1 - _mark);
332 _responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0; 339 _responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0;
333 _state=STATE_SPACE1; 340 _state=STATE_SPACE1;
334 continue; 341 continue;
335 } 342 }
336 else if (ch < HttpTokens.SPACE && ch>=0) 343 else if (ch < HttpTokens.SPACE && ch>=0)
359 366
360 case STATE_STATUS: 367 case STATE_STATUS:
361 if (ch == HttpTokens.SPACE) 368 if (ch == HttpTokens.SPACE)
362 { 369 {
363 // _tok1.update(_mark, _buffer.getIndex() - 1); 370 // _tok1.update(_mark, _buffer.getIndex() - 1);
364 _tok1 = _buffer.toString(_mark, _buffer.getIndex() - 1 - _mark); 371 _tok1 = bufferToString(_mark, _buffer.getIndex() - 1 - _mark);
365 _state = STATE_SPACE2; 372 _state = STATE_SPACE2;
366 continue; 373 continue;
367 } 374 }
368 else if (ch>='0' && ch<='9') 375 else if (ch>='0' && ch<='9')
369 { 376 {
386 393
387 case STATE_URI: 394 case STATE_URI:
388 if (ch == HttpTokens.SPACE) 395 if (ch == HttpTokens.SPACE)
389 { 396 {
390 // _tok1.update(_mark, _buffer.getIndex() - 1); 397 // _tok1.update(_mark, _buffer.getIndex() - 1);
391 _tok1 = _buffer.toString(_mark, _buffer.getIndex() - 1 - _mark); 398 _tok1 = bufferToString(_mark, _buffer.getIndex() - 1 - _mark);
392 _state=STATE_SPACE2; 399 _state=STATE_SPACE2;
393 continue; 400 continue;
394 } 401 }
395 else if (ch < HttpTokens.SPACE && ch>=0) 402 else if (ch < HttpTokens.SPACE && ch>=0)
396 { 403 {
397 // HTTP/0.9 404 // HTTP/0.9
398 _handler.startRequest(_tok0, sliceFromMark().toString(), null); 405 _handler.startRequest(_tok0, sliceFromMark(), null);
399 _persistent = false; 406 _persistent = false;
400 _state = STATE_SEEKING_EOF; 407 _state = STATE_SEEKING_EOF;
401 _handler.headerComplete(); 408 _handler.headerComplete();
402 _handler.messageComplete(_contentPosition); 409 _handler.messageComplete(_contentPosition);
403 return 1; 410 return 1;
439 String version; 446 String version;
440 if (_responseStatus > 0) 447 if (_responseStatus > 0)
441 // _handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,sliceFromMark()); 448 // _handler.startResponse(version=HttpVersions.CACHE.lookup(_tok0), _responseStatus,sliceFromMark());
442 version = _tok0; 449 version = _tok0;
443 else 450 else
444 _handler.startRequest(_tok0, _tok1, version=sliceFromMark().toString()); 451 _handler.startRequest(_tok0, _tok1, version=sliceFromMark());
445 _eol=ch; 452 _eol=ch;
446 _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL; 453 _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL;
447 _state=STATE_HEADER; 454 _state=STATE_HEADER;
448 _tok0 = ""; 455 _tok0 = "";
449 _tok1 = ""; 456 _tok1 = "";
635 switch(ch) 642 switch(ch)
636 { 643 {
637 case HttpTokens.CARRIAGE_RETURN: 644 case HttpTokens.CARRIAGE_RETURN:
638 case HttpTokens.LINE_FEED: 645 case HttpTokens.LINE_FEED:
639 if (_length > 0) { 646 if (_length > 0) {
640 _tok0 = _buffer.toString(_mark, _length); 647 _tok0 = bufferToString(_mark, _length);
641 } 648 }
642 _eol=ch; 649 _eol=ch;
643 _state=STATE_HEADER; 650 _state=STATE_HEADER;
644 break; 651 break;
645 case HttpTokens.COLON: 652 case HttpTokens.COLON:
646 if (_length > 0 && _cached==null) { 653 if (_length > 0 && _cached==null) {
647 _tok0 = _buffer.toString(_mark, _length); 654 _tok0 = bufferToString(_mark, _length);
648 } 655 }
649 _length=-1; 656 _length=-1;
650 _state=STATE_HEADER_VALUE; 657 _state=STATE_HEADER_VALUE;
651 break; 658 break;
652 case HttpTokens.SPACE: 659 case HttpTokens.SPACE:
668 switch(ch) 675 switch(ch)
669 { 676 {
670 case HttpTokens.CARRIAGE_RETURN: 677 case HttpTokens.CARRIAGE_RETURN:
671 case HttpTokens.LINE_FEED: 678 case HttpTokens.LINE_FEED:
672 if (_length > 0) { 679 if (_length > 0) {
673 _tok0 = _buffer.toString(_mark,_length); 680 _tok0 = bufferToString(_mark,_length);
674 } 681 }
675 _eol=ch; 682 _eol=ch;
676 _state=STATE_HEADER; 683 _state=STATE_HEADER;
677 break; 684 break;
678 case HttpTokens.COLON: 685 case HttpTokens.COLON:
679 if (_length > 0 && _cached==null) { 686 if (_length > 0 && _cached==null) {
680 _tok0 = _buffer.toString(_mark,_length); 687 _tok0 = bufferToString(_mark,_length);
681 } 688 }
682 _length=-1; 689 _length=-1;
683 _state=STATE_HEADER_VALUE; 690 _state=STATE_HEADER_VALUE;
684 break; 691 break;
685 case HttpTokens.SPACE: 692 case HttpTokens.SPACE:
701 case HttpTokens.LINE_FEED: 708 case HttpTokens.LINE_FEED:
702 if (_length > 0) 709 if (_length > 0)
703 { 710 {
704 if (_tok1.length() == 0) 711 if (_tok1.length() == 0)
705 // _tok1.update(_mark, _mark + _length); 712 // _tok1.update(_mark, _mark + _length);
706 _tok1 = _buffer.toString(_mark, _length); 713 _tok1 = bufferToString(_mark, _length);
707 else 714 else
708 { 715 {
709 // Continuation line! 716 // Continuation line!
710 if (_multiLineValue == null) _multiLineValue = _tok1; 717 if (_multiLineValue == null) _multiLineValue = _tok1;
711 // _tok1.update(_mark, _mark + _length); 718 // _tok1.update(_mark, _mark + _length);
712 _tok1 = _buffer.toString(_mark, _length); 719 _tok1 = bufferToString(_mark, _length);
713 _multiLineValue += " " + _tok1; 720 _multiLineValue += " " + _tok1;
714 } 721 }
715 } 722 }
716 _eol=ch; 723 _eol=ch;
717 _state=STATE_HEADER; 724 _state=STATE_HEADER;
736 case HttpTokens.LINE_FEED: 743 case HttpTokens.LINE_FEED:
737 if (_length > 0) 744 if (_length > 0)
738 { 745 {
739 if (_tok1.length() == 0) 746 if (_tok1.length() == 0)
740 // _tok1.update(_mark, _mark + _length); 747 // _tok1.update(_mark, _mark + _length);
741 _tok1 = _buffer.toString(_mark, _length); 748 _tok1 = bufferToString(_mark, _length);
742 else 749 else
743 { 750 {
744 // Continuation line! 751 // Continuation line!
745 if (_multiLineValue == null) _multiLineValue = _tok1; 752 if (_multiLineValue == null) _multiLineValue = _tok1;
746 // _tok1.update(_mark, _mark + _length); 753 // _tok1.update(_mark, _mark + _length);
747 _tok1 = _buffer.toString(_mark, _length); 754 _tok1 = bufferToString(_mark, _length);
748 _multiLineValue += " " + _tok1; 755 _multiLineValue += " " + _tok1;
749 } 756 }
750 } 757 }
751 _eol=ch; 758 _eol=ch;
752 _state=STATE_HEADER; 759 _state=STATE_HEADER;