Class OutputBuffer


  • public class OutputBuffer
    extends Object
    Abstraction exposing both byte and character methods to write content to the HTTP messaging system in Grizzly.
    • Field Detail

      • LOGGER

        protected static final Logger LOGGER
      • sendfileEnabled

        protected boolean sendfileEnabled
    • Constructor Detail

      • OutputBuffer

        public OutputBuffer()
    • Method Detail

      • initialize

        public void initialize​(HttpHeader outputHeader,
                               boolean sendfileEnabled,
                               org.glassfish.grizzly.filterchain.FilterChainContext ctx)
      • isAsyncEnabled

        @Deprecated
        public boolean isAsyncEnabled()
        Deprecated.
        will always return true

        Returns true if content will be written in a non-blocking fashion, otherwise returns false.

        Returns:
        true if content will be written in a non-blocking fashion, otherwise returns false.
        Since:
        2.1.2
      • setAsyncEnabled

        @Deprecated
        public void setAsyncEnabled​(boolean asyncEnabled)
        Deprecated.
        Sets the asynchronous processing state of this OutputBuffer.
        Parameters:
        asyncEnabled - true if this OutputBuffer will write content without blocking. @since 2.1.2 @deprecated OutputBuffer always supports async mode
      • prepareCharacterEncoder

        public void prepareCharacterEncoder()
      • getBufferSize

        public int getBufferSize()
      • setBufferSize

        public void setBufferSize​(int bufferSize)
      • reset

        public void reset()
        Reset current response.
        Throws:
        IllegalStateException - if the response has already been committed
      • isClosed

        public boolean isClosed()
        Returns:
        true if this OutputBuffer is closed, otherwise returns false.
      • getBufferedDataSize

        public int getBufferedDataSize()
        Get the number of bytes buffered on OutputBuffer and ready to be sent.
        Returns:
        the number of bytes buffered on OutputBuffer and ready to be sent.
      • recycle

        public void recycle()
        Recycle the output buffer. This should be called when closing the connection.
      • acknowledge

        public void acknowledge()
                         throws IOException
        Acknowledge a HTTP Expect header. The response status code and reason phrase should be set before invoking this method.
        Throws:
        IOException - if an error occurs writing the acknowledgment.
      • sendfile

        public void sendfile​(File file,
                             long offset,
                             long length,
                             org.glassfish.grizzly.CompletionHandler<org.glassfish.grizzly.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.

        Parameters:
        file - the File to transfer.
        offset - the starting offset within the File
        length - the total number of bytes to transfer
        handler - CompletionHandler that will be notified of the transfer progress/completion or failure.
        Throws:
        IllegalArgumentException - 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.
        Since:
        2.2
      • flush

        public void flush()
                   throws IOException
        Flush the response.
        Throws:
        IOException - an underlying I/O error occurred
      • writeByteBuffer

        public void writeByteBuffer​(ByteBuffer byteBuffer)
                             throws IOException

        Writes the contents of the specified ByteBuffer to the client.

        Note, that passed ByteBuffer will be directly used by underlying connection, so it could be reused only if it has been flushed.
        Parameters:
        byteBuffer - the ByteBuffer to write
        Throws:
        IOException - if an error occurs during the write
      • writeBuffer

        public void writeBuffer​(org.glassfish.grizzly.Buffer buffer)
                         throws IOException

        Writes the contents of the specified Buffer to the client.

        Note, that passed Buffer will be directly used by underlying connection, so it could be reused only if it has been flushed.
        Parameters:
        buffer - the Buffer to write
        Throws:
        IOException - if an error occurs during the write
      • canWriteChar

        @Deprecated
        public boolean canWriteChar​(int length)
        Deprecated.
      • canWrite

        @Deprecated
        public boolean canWrite​(int length)
        Deprecated.
        the length parameter will be ignored. Please use canWrite().
        See Also:
        AsyncQueueWriter.canWrite(org.glassfish.grizzly.Connection, int)
      • canWrite

        public boolean canWrite()
        See Also:
        Writer.canWrite(org.glassfish.grizzly.Connection)
      • notifyCanWrite

        @Deprecated
        public void notifyCanWrite​(org.glassfish.grizzly.WriteHandler handler,
                                   int length)
        Deprecated.
        the length parameter will be ignored. Please use notifyCanWrite(org.glassfish.grizzly.WriteHandler).
        See Also:
        AsyncQueueWriter.notifyWritePossible(org.glassfish.grizzly.Connection, org.glassfish.grizzly.WriteHandler, int)
      • notifyCanWrite

        public void notifyCanWrite​(org.glassfish.grizzly.WriteHandler handler)
      • getThreadPool

        protected Executor getThreadPool()
        Returns:
        Executor, which will be used for notifying user registered WriteHandler.