Replypublic class Reply extends Object implements SendableAn object used for sending Content to the requestor. |
Fields Summary |
---|
private Code | code | private Content | content | private boolean | headersOnly | private static String | CRLF | private static Charset | ascii | private ByteBuffer | hbb |
Constructors Summary |
---|
Reply(Code rc, Content c)
this(rc, c, null);
| Reply(Code rc, Content c, Request.Action head)
code = rc;
content = c;
headersOnly = (head == Request.Action.HEAD);
|
Methods Summary |
---|
private java.nio.ByteBuffer | headers()
CharBuffer cb = CharBuffer.allocate(1024);
for (;;) {
try {
cb.put("HTTP/1.0 ").put(code.toString()).put(CRLF);
cb.put("Server: niossl/0.1").put(CRLF);
cb.put("Content-type: ").put(content.type()).put(CRLF);
cb.put("Content-length: ")
.put(Long.toString(content.length())).put(CRLF);
cb.put(CRLF);
break;
} catch (BufferOverflowException x) {
assert(cb.capacity() < (1 << 16));
cb = CharBuffer.allocate(cb.capacity() * 2);
continue;
}
}
cb.flip();
return ascii.encode(cb);
| public void | prepare()
content.prepare();
hbb = headers();
| public void | release()
content.release();
| public boolean | send(ChannelIO cio)
if (hbb == null)
throw new IllegalStateException();
if (hbb.hasRemaining()) {
if (cio.write(hbb) <= 0)
return true;
}
if (!headersOnly) {
if (content.send(cio))
return true;
}
if (!cio.dataFlush())
return true;
return false;
|
|