Mercurial Hosting > luan
comparison src/org/eclipse/jetty/http/AbstractGenerator.java @ 982:dbecd7faa1f5
remove Generator
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 16 Oct 2016 21:40:27 -0600 |
| parents | fef4392f4905 |
| children | 23ec25435b8c |
comparison
equal
deleted
inserted
replaced
| 981:f46de416e219 | 982:dbecd7faa1f5 |
|---|---|
| 36 * Currently this class uses a system parameter "jetty.direct.writers" to control | 36 * Currently this class uses a system parameter "jetty.direct.writers" to control |
| 37 * two optional writer to byte conversions. buffer.writers=true will probably be | 37 * two optional writer to byte conversions. buffer.writers=true will probably be |
| 38 * faster, but will consume more memory. This option is just for testing and tuning. | 38 * faster, but will consume more memory. This option is just for testing and tuning. |
| 39 * | 39 * |
| 40 */ | 40 */ |
| 41 public abstract class AbstractGenerator implements Generator | 41 public abstract class AbstractGenerator |
| 42 { | 42 { |
| 43 private static final Logger LOG = LoggerFactory.getLogger(AbstractGenerator.class); | 43 private static final Logger LOG = LoggerFactory.getLogger(AbstractGenerator.class); |
| 44 | |
| 45 public static final boolean LAST=true; | |
| 46 public static final boolean MORE=false; | |
| 44 | 47 |
| 45 // states | 48 // states |
| 46 public final static int STATE_HEADER = 0; | 49 public final static int STATE_HEADER = 0; |
| 47 public final static int STATE_CONTENT = 2; | 50 public final static int STATE_CONTENT = 2; |
| 48 public final static int STATE_FLUSHING = 3; | 51 public final static int STATE_FLUSHING = 3; |
| 87 public AbstractGenerator(Buffers buffers, EndPoint io) | 90 public AbstractGenerator(Buffers buffers, EndPoint io) |
| 88 { | 91 { |
| 89 this._buffers = buffers; | 92 this._buffers = buffers; |
| 90 this._endp = io; | 93 this._endp = io; |
| 91 } | 94 } |
| 95 | |
| 96 /* ------------------------------------------------------------ */ | |
| 97 /** | |
| 98 * Add content. | |
| 99 * | |
| 100 * @param content | |
| 101 * @param last | |
| 102 * @throws IllegalArgumentException if <code>content</code> is {@link Buffer#isImmutable immutable}. | |
| 103 * @throws IllegalStateException If the request is not expecting any more content, | |
| 104 * or if the buffers are full and cannot be flushed. | |
| 105 * @throws IOException if there is a problem flushing the buffers. | |
| 106 */ | |
| 107 public abstract void addContent(Buffer content, boolean last) throws IOException; | |
| 92 | 108 |
| 93 /* ------------------------------------------------------------------------------- */ | 109 /* ------------------------------------------------------------------------------- */ |
| 94 public abstract boolean isRequest(); | 110 public abstract boolean isRequest(); |
| 95 | 111 |
| 96 /* ------------------------------------------------------------------------------- */ | 112 /* ------------------------------------------------------------------------------- */ |
| 273 _version = version; | 289 _version = version; |
| 274 if (_version==HttpVersions.HTTP_0_9_ORDINAL && _method!=null) | 290 if (_version==HttpVersions.HTTP_0_9_ORDINAL && _method!=null) |
| 275 _noContent=true; | 291 _noContent=true; |
| 276 } | 292 } |
| 277 | 293 |
| 278 /* ------------------------------------------------------------ */ | |
| 279 public int getVersion() | 294 public int getVersion() |
| 280 { | 295 { |
| 281 return _version; | 296 return _version; |
| 282 } | 297 } |
| 283 | 298 |
| 284 /* ------------------------------------------------------------ */ | |
| 285 /** | |
| 286 * @see org.eclipse.jetty.http.Generator#setDate(org.eclipse.jetty.io.Buffer) | |
| 287 */ | |
| 288 public void setDate(Buffer timeStampBuffer) | 299 public void setDate(Buffer timeStampBuffer) |
| 289 { | 300 { |
| 290 _date=timeStampBuffer; | 301 _date=timeStampBuffer; |
| 291 } | 302 } |
| 292 | 303 |
| 460 LOG.debug("sendError: {} {}",code,reason); | 471 LOG.debug("sendError: {} {}",code,reason); |
| 461 setResponse(code, reason); | 472 setResponse(code, reason); |
| 462 if (content != null) | 473 if (content != null) |
| 463 { | 474 { |
| 464 completeHeader(null, false); | 475 completeHeader(null, false); |
| 465 addContent(new View(new ByteArrayBuffer(content)), Generator.LAST); | 476 addContent(new View(new ByteArrayBuffer(content)), LAST); |
| 466 } | 477 } |
| 467 else if (code>=400) | 478 else if (code>=400) |
| 468 { | 479 { |
| 469 completeHeader(null, false); | 480 completeHeader(null, false); |
| 470 addContent(new View(new ByteArrayBuffer("Error: "+(reason==null?(""+code):reason))), Generator.LAST); | 481 addContent(new View(new ByteArrayBuffer("Error: "+(reason==null?(""+code):reason))), LAST); |
| 471 } | 482 } |
| 472 else | 483 else |
| 473 { | 484 { |
| 474 completeHeader(null, true); | 485 completeHeader(null, true); |
| 475 } | 486 } |
