comparison src/org/eclipse/jetty/http/AbstractGenerator.java @ 1046:a8c92b0a08ed

add JBuffer
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 07 Nov 2016 22:39:39 -0700
parents a7319f14ba1e
children 2b769da7f67d
comparison
equal deleted inserted replaced
1045:48506d03e230 1046:a8c92b0a08ed
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.Buffer;
24 import org.eclipse.jetty.io.Buffers; 24 import org.eclipse.jetty.io.Buffers;
25 import org.eclipse.jetty.io.ByteArrayBuffer; 25 import org.eclipse.jetty.io.BufferUtil;
26 import org.eclipse.jetty.io.EndPoint; 26 import org.eclipse.jetty.io.EndPoint;
27 import org.eclipse.jetty.io.EofException; 27 import org.eclipse.jetty.io.EofException;
28 import org.slf4j.Logger; 28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 29 import org.slf4j.LoggerFactory;
30 30
212 int len=reason.length(); 212 int len=reason.length();
213 213
214 // TODO don't hard code 214 // TODO don't hard code
215 if (len>1024) 215 if (len>1024)
216 len=1024; 216 len=1024;
217 _reason = new ByteArrayBuffer(len); 217 _reason = BufferUtil.newBuffer(len);
218 for (int i=0;i<len;i++) 218 for (int i=0;i<len;i++)
219 { 219 {
220 char ch = reason.charAt(i); 220 char ch = reason.charAt(i);
221 if (ch!='\r'&&ch!='\n') 221 if (ch!='\r'&&ch!='\n')
222 _reason.put((byte)ch); 222 _reason.put((byte)ch);
332 LOG.debug("sendError: {} {}",code,reason); 332 LOG.debug("sendError: {} {}",code,reason);
333 setResponse(code, reason); 333 setResponse(code, reason);
334 if (content != null) 334 if (content != null)
335 { 335 {
336 completeHeader(null, false); 336 completeHeader(null, false);
337 addContent(new ByteArrayBuffer(content), LAST); 337 addContent(BufferUtil.wrap(content), LAST);
338 } 338 }
339 else if (code>=400) 339 else if (code>=400)
340 { 340 {
341 completeHeader(null, false); 341 completeHeader(null, false);
342 addContent(new ByteArrayBuffer("Error: "+(reason==null?(""+code):reason)), LAST); 342 addContent(BufferUtil.wrap("Error: "+(reason==null?(""+code):reason)), LAST);
343 } 343 }
344 else 344 else
345 { 345 {
346 completeHeader(null, true); 346 completeHeader(null, true);
347 } 347 }