Top Inners Fields Constructors Methods
org.glassfish.grizzly.servlet

public Class ServletOutputStreamImpl

extends ServletOutputStream
Class Inheritance
Imports
java.io.IOException, org.glassfish.grizzly.WriteHandler, org.glassfish.grizzly.http.io.NIOOutputStream, org.glassfish.grizzly.localization.LogMessages, jakarta.servlet.ServletOutputStream, .WriteListener

Author
Jeanfrancois Arcand

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<Boolean>
private boolean
private NIOOutputStream
private boolean
private final HttpServletResponseImpl
private WriteHandler

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides jakarta.servlet.ServletOutputStream.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.

Will send the buffer to the client.

protected void
public boolean
isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Returns true if it is allowable to call any method that may write data (i.e. write(), print() println() or flush).

pack-priv void
public void
setWriteListener(WriteListener writeListener)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Instructs the ServletOutputStream to invoke the provided WriteListener when it is possible to write

public void
write(int i)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[] b)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.

public void
write(byte[] b, int off, int len)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from jakarta.servlet.ServletOutputStream:
printprintprintprintprintprintprintprintlnprintlnprintlnprintlnprintlnprintlnprintlnprintlnwrite

Field Detail

CAN_WRITE_SCOPEback to summary
private static final ThreadLocal<Boolean> CAN_WRITE_SCOPE
hasSetWriteListenerback to summary
private boolean hasSetWriteListener
outputStreamback to summary
private NIOOutputStream outputStream
prevIsReadyback to summary
private boolean prevIsReady
servletResponseback to summary
private final HttpServletResponseImpl servletResponse
writeHandlerback to summary
private WriteHandler writeHandler

Constructor Detail

ServletOutputStreamImplback to summary
protected ServletOutputStreamImpl(final HttpServletResponseImpl servletResponse)

Method Detail

closeback to summary
public void close() throws IOException

Overrides jakarta.servlet.ServletOutputStream.close.

Implements java.io.Closeable.close.

Doc from jakarta.servlet.ServletOutputStream.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.

If this method is called when the output stream is in non-blocking mode, it will immediately return with the stream effectively closed, even if the stream contains buffered data that is yet to be written to client. The container will write this data out in the background. If this process fails the WriteListener#onError(Throwable) method will be invoked as normal.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.OutputStream.close.

if an I/O error occurs.

flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Will send the buffer to the client.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.OutputStream.flush.

if an I/O error occurs.

initializeback to summary
protected void initialize() throws IOException
isReadyback to summary
public boolean isReady()

Implements abstract jakarta.servlet.ServletOutputStream.isReady.

Doc from jakarta.servlet.ServletOutputStream.isReady.

Returns true if it is allowable to call any method that may write data (i.e. write(), print() println() or flush). In blocking mode, this method will always return true, but a subsequent call to a method that writes data may block. In non-blocking mode this method may return false, in which case it is illegal to call a method that writes data and an IllegalStateException MUST be thrown. When WriteListener#onWritePossible() is called, a call to this method that returned true is implicit.

If this method returns false and a WriteListener has been set via setWriteListener(WriteListener), then container will subsequently invoke WriteListener#onWritePossible() once a write operation becomes possible without blocking. Other than the initial call, WriteListener#onWritePossible() will only be called if and only if this method is called and returns false.

Annotations
@Override
recycleback to summary
pack-priv void recycle()
setWriteListenerback to summary
public void setWriteListener(WriteListener writeListener)

Implements abstract jakarta.servlet.ServletOutputStream.setWriteListener.

Doc from jakarta.servlet.ServletOutputStream.setWriteListener.

Instructs the ServletOutputStream to invoke the provided WriteListener when it is possible to write

Annotations
@Override
writeback to summary
public void write(int i) 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.

Annotations
@Override
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
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).

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
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.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
org.glassfish.grizzly.servlet back to summary

pack-priv Class ServletOutputStreamImpl.WriteHandlerImpl

extends Object
implements WriteHandler
Class Inheritance
  • java.lang.Object
  • org.glassfish.grizzly.servlet.ServletOutputStreamImpl.WriteHandlerImpl
All Implemented Interfaces
org.glassfish.grizzly.WriteHandler

Field Summary

Modifier and TypeField and Description
private WriteListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
public void
onError(final Throwable t)

Implements org.glassfish.grizzly.WriteHandler.onError.

Invoked when an error occurs processing the request asynchronously.

public void
onWritePossible()

Implements org.glassfish.grizzly.WriteHandler.onWritePossible.

This callback will be invoked when the requirements as dictated by writer are met.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

writeListenerback to summary
private WriteListener writeListener

Constructor Detail

WriteHandlerImplback to summary
private WriteHandlerImpl(WriteListener listener)

Method Detail

invokeWriteCallbackback to summary
private void invokeWriteCallback()
onErrorback to summary
public void onError(final Throwable t)

Implements org.glassfish.grizzly.WriteHandler.onError.

Doc from org.glassfish.grizzly.WriteHandler.onError.

Invoked when an error occurs processing the request asynchronously.

Annotations
@Override
onWritePossibleback to summary
public void onWritePossible() throws Exception

Implements org.glassfish.grizzly.WriteHandler.onWritePossible.

Doc from org.glassfish.grizzly.WriteHandler.onWritePossible.

This callback will be invoked when the requirements as dictated by writer are met.

Annotations
@Override
Exceptions
Exception:
Exception might be thrown by the custom handler code. This exception will be delegated for processing to onError(java.lang.Throwable).