Top Description Inners Fields Constructors Methods
org.mortbay.jetty

public abstract Class AbstractGenerator

extends Object
implements Generator
Class Inheritance
All Implemented Interfaces
org.mortbay.jetty.Generator
Known Direct Subclasses
org.mortbay.jetty.HttpGenerator
Imports
java.io.IOException, .OutputStreamWriter, .Writer, java.lang.reflect.Field, .Modifier, javax.servlet.ServletOutputStream, javax.servlet.http.HttpServletResponse, org.mortbay.io.Buffer, .Buffers, .ByteArrayBuffer, .EndPoint, .View, org.mortbay.log.Log, org.mortbay.util.ByteArrayOutputStream2, .StringUtil, .TypeUtil

Abstract Generator. Builds HTTP Messages. Currently this class uses a system parameter "jetty.direct.writers" to control two optional writer to byte conversions. buffer.writers=true will probably be faster, but will consume more memory. This option is just for testing and tuning.
Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class

Field Summary

Modifier and TypeField and Description
private static Buffer[]
protected Buffer
protected Buffers
protected boolean
protected Buffer
protected int
protected long
protected long
protected EndPoint
protected boolean
protected Buffer
protected int
protected boolean
protected Buffer
protected boolean
protected Buffer
private boolean
protected int
protected int
protected String
protected int
private static int
private static byte[]
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public
AbstractGenerator(Buffers
buffer pool
buffers
,
EndPoint io, int
Size of the buffer to allocate for HTTP header
headerBufferSize
,
int
Size of the buffer to allocate for HTTP content
contentBufferSize
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
complete()

Implements org.mortbay.jetty.Generator.complete.

Complete the message.
public abstract void
completeHeader(HttpFields fields, boolean allContentAdded)

Redeclares org.mortbay.jetty.Generator.completeHeader.

pack-priv void
public abstract long
public int

Returns:

Returns the contentBufferSize.
getContentBufferSize
()

Implements org.mortbay.jetty.Generator.getContentBufferSize.

public long

Returns:

Returns the contentWritten.
getContentWritten
()

Implements org.mortbay.jetty.Generator.getContentWritten.

public static String
getReason(int code)

protected static Buffer
getReasonBuffer(int code)

public boolean
public int
public Buffer
public int
public void
increaseContentBufferSize(int
The contentBufferSize to set.
contentBufferSize
)

Implements org.mortbay.jetty.Generator.increaseContentBufferSize.

public boolean
public boolean
public boolean
public boolean
public boolean

Returns:

Returns the head.
isHead
()

public boolean
public boolean

Returns:

false if the connection should be closed after a request has been read, true if it should be used for additional requests.
isPersistent
()

Implements org.mortbay.jetty.Generator.isPersistent.

public boolean
isState(int state)

protected abstract int

Returns:

the available space in the buffer.
prepareUncheckedAddContent
()

Prepare buffer for unchecked writes.

public void
reset(boolean returnBuffers)

Implements org.mortbay.jetty.Generator.reset.

public void
public void
sendError(int code, String reason, String content, boolean close)

Implements org.mortbay.jetty.Generator.sendError.

Utility method to send an error response.
public void
public void
setHead(boolean
The head to set.
head
)

Implements org.mortbay.jetty.Generator.setHead.

public void
public void
public void
setResponse(int
The status code to send.
status
,
String
the status message to send.
reason
)

Implements org.mortbay.jetty.Generator.setResponse.

public void
public void
setVersion(int
The version of the client the response is being sent to (NB. Not the version in the response, which is the version of the server).
version
)

Implements org.mortbay.jetty.Generator.setVersion.

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__reasonsback to summary
private static Buffer[] __reasons
_bufferback to summary
protected Buffer _buffer
_buffersback to summary
protected Buffers _buffers
_closeback to summary
protected boolean _close
_contentback to summary
protected Buffer _content
_contentBufferSizeback to summary
protected int _contentBufferSize
_contentLengthback to summary
protected long _contentLength
_contentWrittenback to summary
protected long _contentWritten
_endpback to summary
protected EndPoint _endp
_headback to summary
protected boolean _head
_headerback to summary
protected Buffer _header
_headerBufferSizeback to summary
protected int _headerBufferSize
_lastback to summary
protected boolean _last
_methodback to summary
protected Buffer _method
_noContentback to summary
protected boolean _noContent
_reasonback to summary
protected Buffer _reason
_sendServerVersionback to summary
private boolean _sendServerVersion
_stateback to summary
protected int _state
_statusback to summary
protected int _status
_uriback to summary
protected String _uri
_versionback to summary
protected int _version
MAX_OUTPUT_CHARSback to summary
private static int MAX_OUTPUT_CHARS
NO_BYTESback to summary
private static byte[] NO_BYTES
STATE_CONTENTback to summary
public static final int STATE_CONTENT
STATE_ENDback to summary
public static final int STATE_END
STATE_FLUSHINGback to summary
public static final int STATE_FLUSHING
STATE_HEADERback to summary
public static final int STATE_HEADER

Constructor Detail

AbstractGeneratorback to summary
public AbstractGenerator(Buffers buffers, EndPoint io, int headerBufferSize, int contentBufferSize)

Constructor.

Parameters
buffers:Buffers

buffer pool

headerBufferSize:int

Size of the buffer to allocate for HTTP header

contentBufferSize:int

Size of the buffer to allocate for HTTP content

Method Detail

completeback to summary
public void complete() throws IOException

Implements org.mortbay.jetty.Generator.complete.

Complete the message.

completeHeaderback to summary
public abstract void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException

Redeclares org.mortbay.jetty.Generator.completeHeader.

completeUncheckedAddContentback to summary
pack-priv void completeUncheckedAddContent()
flushback to summary
public abstract long flush() throws IOException

Redeclares org.mortbay.jetty.Generator.flush.

getContentBufferSizeback to summary
public int getContentBufferSize()

Implements org.mortbay.jetty.Generator.getContentBufferSize.

Returns:int

Returns the contentBufferSize.

getContentWrittenback to summary
public long getContentWritten()

Implements org.mortbay.jetty.Generator.getContentWritten.

Returns:long

Returns the contentWritten.

getReasonback to summary
public static String getReason(int code)
getReasonBufferback to summary
protected static Buffer getReasonBuffer(int code)
getSendServerVersionback to summary
public boolean getSendServerVersion()
getStateback to summary
public int getState()
getUncheckedBufferback to summary
public Buffer getUncheckedBuffer()
getVersionback to summary
public int getVersion()
increaseContentBufferSizeback to summary
public void increaseContentBufferSize(int contentBufferSize)

Implements org.mortbay.jetty.Generator.increaseContentBufferSize.

Parameters
contentBufferSize:int

The contentBufferSize to set.

isBufferFullback to summary
public boolean isBufferFull()

Implements org.mortbay.jetty.Generator.isBufferFull.

isCommittedback to summary
public boolean isCommitted()

Implements org.mortbay.jetty.Generator.isCommitted.

isCompleteback to summary
public boolean isComplete()

Implements org.mortbay.jetty.Generator.isComplete.

isContentWrittenback to summary
public boolean isContentWritten()

Implements org.mortbay.jetty.Generator.isContentWritten.

isHeadback to summary
public boolean isHead()
Returns:boolean

Returns the head.

isIdleback to summary
public boolean isIdle()

Implements org.mortbay.jetty.Generator.isIdle.

isPersistentback to summary
public boolean isPersistent()

Implements org.mortbay.jetty.Generator.isPersistent.

Returns:boolean

false if the connection should be closed after a request has been read, true if it should be used for additional requests.

isStateback to summary
public boolean isState(int state)
prepareUncheckedAddContentback to summary
protected abstract int prepareUncheckedAddContent() throws IOException

Prepare buffer for unchecked writes. Prepare the generator buffer to receive unchecked writes

Returns:int

the available space in the buffer.

resetback to summary
public void reset(boolean returnBuffers)

Implements org.mortbay.jetty.Generator.reset.

resetBufferback to summary
public void resetBuffer()

Implements org.mortbay.jetty.Generator.resetBuffer.

sendErrorback to summary
public void sendError(int code, String reason, String content, boolean close) throws IOException

Implements org.mortbay.jetty.Generator.sendError.

Utility method to send an error response. If the builder is not committed, this call is equivalent to a setResponse, addcontent and complete call.

setContentLengthback to summary
public void setContentLength(long value)

Implements org.mortbay.jetty.Generator.setContentLength.

setHeadback to summary
public void setHead(boolean head)

Implements org.mortbay.jetty.Generator.setHead.

Parameters
head:boolean

The head to set.

setPersistentback to summary
public void setPersistent(boolean persistent)

Implements org.mortbay.jetty.Generator.setPersistent.

setRequestback to summary
public void setRequest(String method, String uri)

Implements org.mortbay.jetty.Generator.setRequest.

setResponseback to summary
public void setResponse(int status, String reason)

Implements org.mortbay.jetty.Generator.setResponse.

Parameters
status:int

The status code to send.

reason:String

the status message to send.

setSendServerVersionback to summary
public void setSendServerVersion(boolean sendServerVersion)

Implements org.mortbay.jetty.Generator.setSendServerVersion.

setVersionback to summary
public void setVersion(int version)

Implements org.mortbay.jetty.Generator.setVersion.

Parameters
version:int

The version of the client the response is being sent to (NB. Not the version in the response, which is the version of the server).

uncheckedAddContentback to summary
pack-priv void uncheckedAddContent(int b)
org.mortbay.jetty back to summary

public Class AbstractGenerator.Output

extends ServletOutputStream
Class Inheritance
Known Direct Subclasses
org.mortbay.jetty.HttpConnection.Output

Output.

Implements javax.servlet.ServletOutputStream from the javax.servlet package.

A ServletOutputStream implementation that writes content to a AbstractGenerator. The class is designed to be reused and can be reopened after a close.

Field Summary

Modifier and TypeField and Description
protected ByteArrayBuffer
pack-priv ByteArrayOutputStream2
pack-priv String
pack-priv char[]
protected boolean
pack-priv Writer
protected AbstractGenerator
protected long

Constructor Summary

AccessConstructor and Description
public
Output(AbstractGenerator generator, long maxIdleTime)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.
public void
print(String
the String to send to the client
s
)

Overrides javax.servlet.ServletOutputStream.print.

Writes a String to the client, without a carriage return-line feed (CRLF) character at the end.
pack-priv void
public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(byte[]
the data.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
private void
write(Buffer buffer)

Inherited from javax.servlet.ServletOutputStream:
isReadyprintprintprintprintprintprintprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnsetWriteListener

Field Detail

_bufback to summary
protected ByteArrayBuffer _buf
_bytesback to summary
pack-priv ByteArrayOutputStream2 _bytes
_characterEncodingback to summary
pack-priv String _characterEncoding
_charsback to summary
pack-priv char[] _chars
_closedback to summary
protected boolean _closed
_converterback to summary
pack-priv Writer _converter
_generatorback to summary
protected AbstractGenerator _generator
_maxIdleTimeback to summary
protected long _maxIdleTime

Constructor Detail

Outputback to summary
public Output(AbstractGenerator generator, long maxIdleTime)

Method Detail

blockForOutputback to summary
pack-priv void blockForOutput() throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Exceptions
IOException:
if an I/O error occurs.
printback to summary
public void print(String s) throws IOException

Overrides javax.servlet.ServletOutputStream.print.

Doc from javax.servlet.ServletOutputStream.print.

Writes a String to the client, without a carriage return-line feed (CRLF) character at the end.

Parameters
s:String

the String to send to the client

Exceptions
IOException:
if an input or output exception occurred
reopenback to summary
pack-priv void reopen()
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
b:byte[]

the data.

Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
private void write(Buffer buffer) throws IOException
org.mortbay.jetty back to summary

public Class AbstractGenerator.OutputWriter

extends Writer
Class Inheritance
Known Direct Subclasses
org.mortbay.jetty.HttpConnection.OutputWriter

OutputWriter. A writer that can wrap a Output stream and provide character encodings. The UTF-8 encoding is done by this class and no additional buffers or Writers are used. The UTF-8 code was inspired by http://javolution.org

Field Summary

Modifier and TypeField and Description
pack-priv AbstractGenerator
pack-priv AbstractGenerator.Output
pack-priv int
pack-priv int
private static final int
private static final int
private static final int
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.
public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.
private Writer
public void
public void
write(String
A String
s
,
int
Offset from which to start writing characters
offset
,
int
Number of characters to write
length
)

Overrides java.io.Writer.write.

Writes a portion of a string.
public void
write(char[]
Array of characters
s
,
int
Offset from which to start writing characters
offset
,
int
Number of characters to write
length
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.
Inherited from java.io.Writer:
appendappendappendnullWriterwritewritewrite

Field Detail

_generatorback to summary
pack-priv AbstractGenerator _generator
_outback to summary
pack-priv AbstractGenerator.Output _out
_surrogateback to summary
pack-priv int _surrogate
_writeModeback to summary
pack-priv int _writeMode
WRITE_CONVback to summary
private static final int WRITE_CONV
WRITE_ISO1back to summary
private static final int WRITE_ISO1
WRITE_UTF8back to summary
private static final int WRITE_UTF8

Constructor Detail

OutputWriterback to summary
public OutputWriter(AbstractGenerator.Output out)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Exceptions
IOException:
If an I/O error occurs
getConverterback to summary
private Writer getConverter() throws IOException
setCharacterEncodingback to summary
public void setCharacterEncoding(String encoding)
writeback to summary
public void write(String s, int offset, int length) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Parameters
s:String

A String

offset:int

Offset from which to start writing characters

length:int

Number of characters to write

Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] s, int offset, int length) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
s:char[]

Array of characters

offset:int

Offset from which to start writing characters

length:int

Number of characters to write

Exceptions
IOException:
If an I/O error occurs