comparison src/org/eclipse/jetty/http/HttpGenerator.java @ 1068:9d357b9e4bcb

fix BufferUtil.newBuffer()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 10 Nov 2016 00:23:05 -0700
parents 56b515be91e1
children 7dd6ec499000
comparison
equal deleted inserted replaced
1067:56b515be91e1 1068:9d357b9e4bcb
148 if (_content != null && _content.remaining()>0) 148 if (_content != null && _content.remaining()>0)
149 { 149 {
150 if (_bufferChunked) 150 if (_bufferChunked)
151 { 151 {
152 JBuffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining()); 152 JBuffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining());
153 nc.clear();
154 nc.putQ(_content); 153 nc.putQ(_content);
155 nc.putQ(HttpTokens.CRLF); 154 nc.putQ(HttpTokens.CRLF);
156 BufferUtil.putHexInt(nc, content.remaining()); 155 BufferUtil.putHexInt(nc, content.remaining());
157 nc.putQ(HttpTokens.CRLF); 156 nc.putQ(HttpTokens.CRLF);
158 nc.putQ(content); 157 nc.putQ(content);
160 content = nc; 159 content = nc;
161 } 160 }
162 else 161 else
163 { 162 {
164 JBuffer nc = _buffers.getBuffer(_content.remaining()+content.remaining()); 163 JBuffer nc = _buffers.getBuffer(_content.remaining()+content.remaining());
165 nc.clear();
166 nc.putQ(_content); 164 nc.putQ(_content);
167 nc.putQ(content); 165 nc.putQ(content);
168 nc.flip(); 166 nc.flip();
169 content = nc; 167 content = nc;
170 } 168 }
184 { 182 {
185 _bypass = true; 183 _bypass = true;
186 } 184 }
187 else if (!_bufferChunked) 185 else if (!_bufferChunked)
188 { 186 {
189 // Yes - so we better check we have a buffer
190 if (_buffer == null)
191 _buffer = _buffers.getBuffer();
192
193 // Copy _content to buffer; 187 // Copy _content to buffer;
194 int len = _buffer.put(_content); 188 int len = _buffer.put(_content);
195 _content.skip(len); 189 _content.skip(len);
196 if (_content.remaining() == 0) 190 if (_content.remaining() == 0)
197 _content = null; 191 _content = null;
924 private boolean _head = false; 918 private boolean _head = false;
925 private boolean _noContent = false; 919 private boolean _noContent = false;
926 private Boolean _persistent = null; 920 private Boolean _persistent = null;
927 921
928 private final JBuffer _header; // JBuffer for HTTP header (and maybe small _content) 922 private final JBuffer _header; // JBuffer for HTTP header (and maybe small _content)
929 private JBuffer _buffer; // JBuffer for copy of passed _content 923 private final JBuffer _buffer; // JBuffer for copy of passed _content
930 private JBuffer _content; // JBuffer passed to addContent 924 private JBuffer _content; // JBuffer passed to addContent
931 925
932 926
933 public HttpGenerator(Buffers buffers, EndPoint io) 927 public HttpGenerator(Buffers buffers, EndPoint io)
934 { 928 {
935 this._buffers = buffers; 929 this._buffers = buffers;
936 this._endp = io; 930 this._endp = io;
937 _header = _buffers.getHeader(); 931 _header = _buffers.getHeader();
938 _header.clear(); 932 _buffer = _buffers.getBuffer();
933 _buffer.limit(0);
939 } 934 }
940 935
941 public final boolean isOpen() 936 public final boolean isOpen()
942 { 937 {
943 return _endp.isOpen(); 938 return _endp.isOpen();
961 /** 956 /**
962 * @return Returns the contentBufferSize. 957 * @return Returns the contentBufferSize.
963 */ 958 */
964 public final int getContentBufferSize() 959 public final int getContentBufferSize()
965 { 960 {
966 if (_buffer==null)
967 _buffer = _buffers.getBuffer();
968 return _buffer.capacity(); 961 return _buffer.capacity();
969 } 962 }
970 963
971 public final JBuffer getUncheckedBuffer() 964 public final JBuffer getUncheckedBuffer()
972 { 965 {
973 if (_buffer == null)
974 _buffer = _buffers.getBuffer();
975 return _buffer; 966 return _buffer;
976 } 967 }
977 968
978 public final boolean isComplete() 969 public final boolean isComplete()
979 { 970 {
1045 1036
1046 // TODO don't hard code 1037 // TODO don't hard code
1047 if (len>1024) 1038 if (len>1024)
1048 len=1024; 1039 len=1024;
1049 _reason = BufferUtil.newBuffer(len); 1040 _reason = BufferUtil.newBuffer(len);
1050 _reason.clear();
1051 for (int i=0;i<len;i++) 1041 for (int i=0;i<len;i++)
1052 { 1042 {
1053 char ch = reason.charAt(i); 1043 char ch = reason.charAt(i);
1054 if (ch!='\r'&&ch!='\n') 1044 if (ch!='\r'&&ch!='\n')
1055 _reason.putQ((byte)ch); 1045 _reason.putQ((byte)ch);