public class OutputBuffer extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
OutputBuffer.LifeCycleListener |
Modifier and Type | Field and Description |
---|---|
protected static Logger |
LOGGER |
protected boolean |
sendfileEnabled |
Constructor and Description |
---|
OutputBuffer() |
Modifier and Type | Method and Description |
---|---|
void |
acknowledge()
Acknowledge a HTTP
Expect header. |
boolean |
canWrite() |
boolean |
canWrite(int length)
Deprecated.
the
length parameter will be ignored. Please use canWrite() . |
boolean |
canWriteChar(int length)
Deprecated.
|
void |
close() |
void |
endRequest() |
void |
flush()
Flush the response.
|
int |
getBufferedDataSize()
Get the number of bytes buffered on OutputBuffer and ready to be sent.
|
int |
getBufferSize() |
void |
initialize(HttpHeader outputHeader,
boolean sendfileEnabled,
FilterChainContext ctx) |
boolean |
isAsyncEnabled()
Deprecated.
will always return true
|
boolean |
isClosed() |
void |
notifyCanWrite(WriteHandler handler) |
void |
notifyCanWrite(WriteHandler handler,
int length)
Deprecated.
the
length parameter will be ignored. Please use notifyCanWrite(org.glassfish.grizzly.WriteHandler) . |
void |
prepareCharacterEncoder() |
void |
recycle()
Recycle the output buffer.
|
void |
registerLifeCycleListener(OutputBuffer.LifeCycleListener listener) |
boolean |
removeLifeCycleListener(OutputBuffer.LifeCycleListener listener) |
void |
reset()
Reset current response.
|
void |
sendfile(File file,
CompletionHandler<WriteResult> handler)
Calls
write(file, 0, file.length()) . |
void |
sendfile(File file,
long offset,
long length,
CompletionHandler<WriteResult> handler)
Will use
FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
to send file to the remote endpoint. |
void |
setAsyncEnabled(boolean asyncEnabled)
Deprecated.
OutputBuffer always supports async mode
|
void |
setBufferSize(int bufferSize) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(char[] cbuf) |
void |
write(char[] cbuf,
int off,
int len) |
void |
write(String str) |
void |
write(String str,
int off,
int len) |
void |
writeBuffer(Buffer buffer)
Writes the contents of the specified
Buffer to the client. |
void |
writeByte(int b) |
void |
writeByteBuffer(ByteBuffer byteBuffer)
Writes the contents of the specified
ByteBuffer to the client. |
void |
writeChar(int c) |
protected static final Logger LOGGER
protected boolean sendfileEnabled
public void initialize(HttpHeader outputHeader, boolean sendfileEnabled, FilterChainContext ctx)
public boolean isAsyncEnabled()
Returns true
if content will be written in a non-blocking
fashion, otherwise returns false
.
true
if content will be written in a non-blocking
fashion, otherwise returns false
.public void setAsyncEnabled(boolean asyncEnabled)
OutputBuffer
.asyncEnabled
- true
if this OutputBuffer
will write content without blocking.
public void prepareCharacterEncoder()
public int getBufferSize()
public void registerLifeCycleListener(OutputBuffer.LifeCycleListener listener)
public boolean removeLifeCycleListener(OutputBuffer.LifeCycleListener listener)
public void setBufferSize(int bufferSize)
public void reset()
IllegalStateException
- if the response has already been committedpublic boolean isClosed()
true
if this OutputBuffer is closed, otherwise
returns false
.public int getBufferedDataSize()
public void recycle()
public void endRequest() throws IOException
IOException
public void acknowledge() throws IOException
Expect
header. The response status
code and reason phrase should be set before invoking this method.IOException
- if an error occurs writing the acknowledgment.public void writeChar(int c) throws IOException
IOException
public void write(char[] cbuf, int off, int len) throws IOException
IOException
public void write(char[] cbuf) throws IOException
IOException
public void write(String str) throws IOException
IOException
public void write(String str, int off, int len) throws IOException
IOException
public void writeByte(int b) throws IOException
IOException
public void write(byte[] b) throws IOException
IOException
public void sendfile(File file, CompletionHandler<WriteResult> handler)
Calls write(file, 0, file.length())
.
file
- the File
to transfer.handler
- CompletionHandler
that will be notified
of the transfer progress/completion or failure.IOException
- if an error occurs during the transferIllegalArgumentException
- if file
is nullsendfile(java.io.File, long, long, org.glassfish.grizzly.CompletionHandler)
public void sendfile(File file, long offset, long length, CompletionHandler<WriteResult> handler)
Will use FileChannel.transferTo(long, long, java.nio.channels.WritableByteChannel)
to send file to the remote endpoint. Note that all headers necessary
for the file transfer must be set prior to invoking this method as this will
case the HTTP header to be flushed to the client prior to sending the file
content. This should also be the last call to write any content to the remote
endpoint.
It's required that the response be suspended when using this functionality. It will be assumed that if the response wasn't suspended when this method is called, that it's desired that this method manages the suspend/resume cycle.
file
- the File
to transfer.offset
- the starting offset within the Filelength
- the total number of bytes to transferhandler
- CompletionHandler
that will be notified
of the transfer progress/completion or failure.IOException
- if an error occurs during the transferIOException
- if an I/O error occursIllegalArgumentException
- if the response has already been committed
at the time this method was invoked.IllegalStateException
- if a file transfer request has already
been made or if send file support isn't
available.IllegalStateException
- if the response was in a suspended state
when this method was invoked, but no
CompletionHandler
was provided.public void write(byte[] b, int off, int len) throws IOException
IOException
public void close() throws IOException
IOException
public void flush() throws IOException
IOException
- an underlying I/O error occurredpublic void writeByteBuffer(ByteBuffer byteBuffer) throws IOException
Writes the contents of the specified ByteBuffer
to the client.
ByteBuffer
will be directly used by underlying
connection, so it could be reused only if it has been flushed.byteBuffer
- the ByteBuffer
to writeIOException
- if an error occurs during the writepublic void writeBuffer(Buffer buffer) throws IOException
Writes the contents of the specified Buffer
to the client.
Buffer
will be directly used by underlying
connection, so it could be reused only if it has been flushed.buffer
- the Buffer
to writeIOException
- if an error occurs during the write@Deprecated public boolean canWriteChar(int length)
public boolean canWrite(int length)
length
parameter will be ignored. Please use canWrite()
.public boolean canWrite()
public void notifyCanWrite(WriteHandler handler, int length)
length
parameter will be ignored. Please use notifyCanWrite(org.glassfish.grizzly.WriteHandler)
.public void notifyCanWrite(WriteHandler handler)
Copyright © 2014 Oracle Corporation. All rights reserved.