FileDocCategorySizeDatePackage
Reply.javaAPI DocSun JDK 1.5.0 Example4042Sat Jan 08 15:08:43 GMT 2005None

Reply

public class Reply extends Object implements Sendable
An object used for sending Content to the requestor.
author
Mark Reinhold
author
Brad R. Wetmore
version
1.2, 04/07/26

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.ByteBufferheaders()


       
	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 voidprepare()

	content.prepare();
	hbb = headers();
    
public voidrelease()

	content.release();
    
public booleansend(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;