Class InputBuffer


  • public class InputBuffer
    extends Object
    Abstraction exposing both byte and character methods to read content from the HTTP messaging system in Grizzly.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Map<String,​String> trailers
      Trailer headers, if any.
    • Constructor Summary

      Constructors 
      Constructor Description
      InputBuffer()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean append​(HttpContent httpContent)
      Appends the specified Buffer to the internal composite Buffer.
      boolean areTrailersAvailable()  
      int available()  
      int availableChar()  
      protected HttpContent blockingRead()
      Read next chunk of data in this thread, block if needed.
      void close()  
      void fillFully​(int length)
      /** Fill the buffer (blocking) up to the requested length.
      protected void finished()
      When invoked, this method will call ReadHandler.onAllDataRead() on the current ReadHandler (if any).
      org.glassfish.grizzly.Buffer getBuffer()
      Returns the duplicate of the underlying Buffer used to buffer incoming request data.
      org.glassfish.grizzly.ReadHandler getReadHandler()  
      protected Executor getThreadPool()  
      Map<String,​String> getTrailers()  
      void initialize​(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
      Per-request initialization required for the InputBuffer to function properly.
      void initiateAsyncronousDataReceiving()
      Initiates asynchronous data receiving.
      boolean isAsyncEnabled()
      Deprecated.
      will always return true
      boolean isClosed()  
      boolean isFinished()  
      void mark​(int readAheadLimit)
      Supported with binary and character data.
      boolean markSupported()
      Only supported with binary data.
      void notifyAvailable​(org.glassfish.grizzly.ReadHandler handler)
      Installs a ReadHandler that will be notified when any data becomes available to read without blocking.
      void notifyAvailable​(org.glassfish.grizzly.ReadHandler handler, int size)
      Installs a ReadHandler that will be notified when the specified amount of data is available to be read without blocking.
      void processingChars()
      This method should be called if the InputBuffer is being used in conjunction with a Reader implementation.
      int read​(byte[] b, int off, int len)  
      int read​(char[] cbuf, int off, int len)  
      int read​(CharBuffer target)  
      org.glassfish.grizzly.Buffer readBuffer()  
      org.glassfish.grizzly.Buffer readBuffer​(int size)  
      int readByte()
      This method always blocks.
      int readChar()  
      boolean ready()  
      int readyData()
      Depending on the InputBuffer mode, method will return either number of available bytes or characters ready to be read without blocking.
      void recycle()
      Recycle this InputBuffer for reuse.
      void replayPayload​(org.glassfish.grizzly.Buffer buffer)  
      void reset()
      Only supported with binary data.
      void setAsyncEnabled​(boolean asyncEnabled)
      Deprecated.
      void setDefaultEncoding​(String encoding)
      Set the default character encoding for this InputBuffer, which would be applied if no encoding was explicitly set on HTTP HttpRequestPacket and character decoding wasn't started yet.
      long skip​(long n)
      Skips the specified number of bytes/characters.
      long skip​(long n, boolean block)
      Deprecated.
      pls.
      void terminate()
      Invoke ReadHandler.onError(Throwable) (assuming a ReadHandler is available) } passing a {#link CancellationException} if the current Connection is open, or a {#link EOFException} if the connection was unexpectedly closed.
      protected void updateInputContentBuffer​(org.glassfish.grizzly.Buffer buffer)  
    • Field Detail

      • trailers

        protected Map<String,​String> trailers
        Trailer headers, if any.
    • Constructor Detail

      • InputBuffer

        public InputBuffer()
    • Method Detail

      • initialize

        public void initialize​(HttpHeader httpHeader,
                               org.glassfish.grizzly.filterchain.FilterChainContext ctx)

        Per-request initialization required for the InputBuffer to function properly.

        Parameters:
        httpHeader - the header from which input will be obtained.
        ctx - the FilterChainContext for the chain processing this request
      • setDefaultEncoding

        public void setDefaultEncoding​(String encoding)
        Set the default character encoding for this InputBuffer, which would be applied if no encoding was explicitly set on HTTP HttpRequestPacket and character decoding wasn't started yet.
      • recycle

        public void recycle()

        Recycle this InputBuffer for reuse.

      • processingChars

        public void processingChars()

        This method should be called if the InputBuffer is being used in conjunction with a Reader implementation. If this method is not called, any character-based methods called on this InputBuffer will throw a IllegalStateException.

      • readyData

        public int readyData()
        Depending on the InputBuffer mode, method will return either number of available bytes or characters ready to be read without blocking.
        Returns:
        depending on the InputBuffer mode, method will return either number of available bytes or characters ready to be read without blocking.
      • getBuffer

        public org.glassfish.grizzly.Buffer getBuffer()
        Returns the duplicate of the underlying Buffer used to buffer incoming request data. The content of the returned buffer will be that of the underlying buffer. Changes to returned buffer's content will be visible in the underlying buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
        Returns:
        the duplicate of the underlying Buffer used to buffer incoming request data.
      • readBuffer

        public org.glassfish.grizzly.Buffer readBuffer()
        Returns:
        the underlying Buffer used to buffer incoming request data. Unlike getBuffer(), this method detaches the returned Buffer, so user code becomes responsible for handling the Buffer.
      • readBuffer

        public org.glassfish.grizzly.Buffer readBuffer​(int size)
        Parameters:
        size - the requested size of the Buffer to be returned.
        Returns:
        the Buffer of a given size, which represents a chunk of the underlying Buffer which contains incoming request data. This method detaches the returned Buffer, so user code becomes responsible for handling its life-cycle.
      • getReadHandler

        public org.glassfish.grizzly.ReadHandler getReadHandler()
        Returns:
        the ReadHandler current in use, if any.
      • fillFully

        public void fillFully​(int length)
                       throws IOException
        /** Fill the buffer (blocking) up to the requested length.
        Parameters:
        length - how much content should attempt to buffer, -1 means buffer entire request.
        Throws:
        IOException - if an error occurs reading data from the wire.
      • availableChar

        public int availableChar()
      • areTrailersAvailable

        public boolean areTrailersAvailable()
      • finished

        protected void finished()
        When invoked, this method will call ReadHandler.onAllDataRead() on the current ReadHandler (if any). This method shouldn't be invoked by developers directly.
      • replayPayload

        public void replayPayload​(org.glassfish.grizzly.Buffer buffer)
      • isFinished

        public boolean isFinished()
        Returns:
        true if all request data has been read, otherwise returns false.
      • isClosed

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

        public void notifyAvailable​(org.glassfish.grizzly.ReadHandler handler)
        Installs a ReadHandler that will be notified when any data becomes available to read without blocking.
        Parameters:
        handler - the ReadHandler to invoke.
        Throws:
        IllegalArgumentException - if handler is null.
        IllegalStateException - if an attempt is made to register a handler before an existing registered handler has been invoked or if all request data has already been read.
      • notifyAvailable

        public void notifyAvailable​(org.glassfish.grizzly.ReadHandler handler,
                                    int size)
        Installs a ReadHandler that will be notified when the specified amount of data is available to be read without blocking.
        Parameters:
        handler - the ReadHandler to invoke.
        size - the minimum number of bytes that must be available before the ReadHandler is notified.
        Throws:
        IllegalArgumentException - if handler is null, or if size is less or equal to zero.
        IllegalStateException - if an attempt is made to register a handler before an existing registered handler has been invoked.
      • append

        public boolean append​(HttpContent httpContent)
                       throws IOException
        Appends the specified Buffer to the internal composite Buffer.
        Parameters:
        httpContent - the HttpContent to append
        Returns:
        true if ReadHandler callback was invoked, otherwise returns false.
        Throws:
        IOException - if an error occurs appending the Buffer
      • isAsyncEnabled

        @Deprecated
        public boolean isAsyncEnabled()
        Deprecated.
        will always return true
        Returns:
        if this buffer is being used to process asynchronous data.
      • setAsyncEnabled

        @Deprecated
        public void setAsyncEnabled​(boolean asyncEnabled)
        Deprecated.
        Sets the asynchronous processing state of this InputBuffer.
        Parameters:
        asyncEnabled - true if this InputBuffer is to be used to process asynchronous request data. @deprecated InputBuffer always supports async mode
      • terminate

        public void terminate()

        Invoke ReadHandler.onError(Throwable) (assuming a ReadHandler is available) } passing a {#link CancellationException} if the current Connection is open, or a {#link EOFException} if the connection was unexpectedly closed.

        Since:
        2.0.1
      • initiateAsyncronousDataReceiving

        public void initiateAsyncronousDataReceiving()
        Initiates asynchronous data receiving. This is service method, usually users don't have to call it explicitly.
      • getThreadPool

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

        protected void updateInputContentBuffer​(org.glassfish.grizzly.Buffer buffer)