Class Buffer


  • @Deprecated
    public class Buffer
    extends java.lang.Object
    Deprecated.
    Will be removed to favor lower-level network extensions allowing more control at the Restlet API level.
    Wrapper around a byte buffer and its state.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer bytes
      Deprecated.
      The byte buffer.
      private int fillBegin
      Deprecated.
      The index of the buffer's beginning while filling.
      private BufferState state
      Deprecated.
      The byte buffer IO state.
    • Constructor Summary

      Constructors 
      Constructor Description
      Buffer​(int bufferSize)
      Deprecated.
      Constructor.
      Buffer​(int bufferSize, boolean direct)
      Deprecated.
      Constructor.
      Buffer​(java.nio.ByteBuffer byteBuffer)
      Deprecated.
      Constructor.
      Buffer​(java.nio.ByteBuffer byteBuffer, BufferState byteBufferState)
      Deprecated.
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void beforeDrain()
      Deprecated.
      Ensure that the buffer is ready to be drained, flipping it if necessary only.
      void beforeFill()
      Deprecated.
      Ensure that the buffer is ready to be filled, flipping it if necessary only.
      boolean canCompact()
      Deprecated.
      Indicates if a compacting operation can be beneficial.
      boolean canDrain()
      Deprecated.
      Indicates if more bytes can be drained.
      boolean canFill()
      Deprecated.
      Indicates if more bytes can be filled in.
      int capacity()
      Deprecated.
      Returns the maximum capacity of this buffer.
      void clear()
      Deprecated.
      Recycles the buffer so it can be reused.
      void compact()
      Deprecated.
      Compacts the bytes to be drained at the beginning of the buffer.
      boolean couldDrain()
      Deprecated.
      Indicates if bytes could be drained by flipping the buffer.
      boolean couldFill()
      Deprecated.
      Indicates if more bytes could be filled in.
      private static java.nio.ByteBuffer createByteBuffer​(int bufferSize, boolean direct)
      Deprecated.
      Creates a new byte buffer.
      int drain()
      Deprecated.
      Drains the next byte in the buffer and returns it as an integer.
      void drain​(byte[] targetArray, int offset, int length)
      Deprecated.
      Drains the buffer into a byte array.
      BufferState drain​(java.lang.StringBuilder lineBuilder, BufferState builderState)
      Deprecated.
      Drains the buffer into a line builder (start line or header line).
      int drain​(java.nio.ByteBuffer targetBuffer)
      Deprecated.
      Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.
      int drain​(java.nio.ByteBuffer targetBuffer, long maxDrained)
      Deprecated.
      Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.
      int drain​(java.nio.channels.WritableByteChannel wbc)
      Deprecated.
      Drains the byte buffer by attempting to write as much as possible on the given channel.
      void fill​(byte[] sourceBuffer)
      Deprecated.
      Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.
      void fill​(java.lang.String source)
      Deprecated.
      Fills the byte buffer by copying as many bytes as possible from the source string, using the default platform encoding.
      int fill​(java.nio.ByteBuffer sourceBuffer)
      Deprecated.
      Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.
      int fill​(java.nio.ByteBuffer sourceBuffer, long maxFilled)
      Deprecated.
      Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.
      int fill​(java.nio.channels.ReadableByteChannel sourceChannel)
      Deprecated.
      Refills the byte buffer.
      void flip()
      Deprecated.
      Flip from draining to filling or the other way around.
      java.nio.ByteBuffer getBytes()
      Deprecated.
      Returns the byte buffer.
      java.lang.Object getLock()
      Deprecated.
      Returns the lock on which multiple thread can synchronize to ensure safe access to the underlying byte buffer which isn't thread safe.
      BufferState getState()
      Deprecated.
      Returns the byte buffer IO state.
      boolean hasRemaining()
      Deprecated.
      Indicates if the buffer has remaining bytes to be read or written.
      boolean isDraining()
      Deprecated.
      Indicates if the buffer state has the BufferState.DRAINING value.
      boolean isEmpty()
      Deprecated.
      Indicates if the buffer is empty in either filling or draining state.
      boolean isFilling()
      Deprecated.
      Indicates if the buffer state has the BufferState.FILLING value.
      int process​(BufferProcessor processor, int maxDrained, java.lang.Object... args)
      Deprecated.
      Processes as a loop the IO event by draining or filling the IO buffer.
      int remaining()
      Deprecated.
      Returns the number of bytes that can be read or written in the byte buffer.
      void setState​(BufferState byteBufferState)
      Deprecated.
      Sets the byte buffer IO state.
      java.lang.String toString()
      Deprecated.
       
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • bytes

        private final java.nio.ByteBuffer bytes
        Deprecated.
        The byte buffer.
      • fillBegin

        private volatile int fillBegin
        Deprecated.
        The index of the buffer's beginning while filling.
      • state

        private volatile BufferState state
        Deprecated.
        The byte buffer IO state.
    • Constructor Detail

      • Buffer

        public Buffer​(java.nio.ByteBuffer byteBuffer)
        Deprecated.
        Constructor.
        Parameters:
        byteBuffer - The byte buffer wrapped.
      • Buffer

        public Buffer​(java.nio.ByteBuffer byteBuffer,
                      BufferState byteBufferState)
        Deprecated.
        Constructor.
        Parameters:
        byteBuffer - The byte buffer wrapped.
        byteBufferState - The initial byte buffer state.
      • Buffer

        public Buffer​(int bufferSize)
        Deprecated.
        Constructor. Allocates a new non-direct byte buffer.
        Parameters:
        bufferSize - The byte buffer size.
      • Buffer

        public Buffer​(int bufferSize,
                      boolean direct)
        Deprecated.
        Constructor. Allocates a new byte buffer using ByteBuffer.allocate(int) or ByteBuffer.allocateDirect(int) methods.
        Parameters:
        bufferSize - The byte buffer size.
        direct - Indicates if a direct NIO buffer should be created.
    • Method Detail

      • createByteBuffer

        private static java.nio.ByteBuffer createByteBuffer​(int bufferSize,
                                                            boolean direct)
        Deprecated.
        Creates a new byte buffer.
        Parameters:
        bufferSize - The buffer size.
        direct - Indicates if a direct NIO buffer should be created.
        Returns:
        The created byte buffer.
      • beforeDrain

        public void beforeDrain()
        Deprecated.
        Ensure that the buffer is ready to be drained, flipping it if necessary only.
      • beforeFill

        public void beforeFill()
        Deprecated.
        Ensure that the buffer is ready to be filled, flipping it if necessary only.
      • canCompact

        public boolean canCompact()
        Deprecated.
        Indicates if a compacting operation can be beneficial.
        Returns:
        True if a compacting operation can be beneficial.
      • canDrain

        public boolean canDrain()
        Deprecated.
        Indicates if more bytes can be drained.
        Returns:
        True if more bytes can be drained.
      • canFill

        public boolean canFill()
        Deprecated.
        Indicates if more bytes can be filled in.
        Returns:
        True if more bytes can be filled in.
      • capacity

        public final int capacity()
        Deprecated.
        Returns the maximum capacity of this buffer.
        Returns:
        The maximum capacity of this buffer.
      • clear

        public void clear()
        Deprecated.
        Recycles the buffer so it can be reused.
      • compact

        public void compact()
        Deprecated.
        Compacts the bytes to be drained at the beginning of the buffer.
      • couldDrain

        public boolean couldDrain()
        Deprecated.
        Indicates if bytes could be drained by flipping the buffer.
        Returns:
        True if bytes could be drained.
      • couldFill

        public boolean couldFill()
        Deprecated.
        Indicates if more bytes could be filled in.
        Returns:
        True if more bytes could be filled in.
      • drain

        public int drain()
        Deprecated.
        Drains the next byte in the buffer and returns it as an integer.
        Returns:
        The next byte in the buffer;
      • drain

        public void drain​(byte[] targetArray,
                          int offset,
                          int length)
        Deprecated.
        Drains the buffer into a byte array.
        Parameters:
        targetArray - The target byte array.
        offset - The target offset.
        length - The number of bytes to drain.
      • drain

        public int drain​(java.nio.ByteBuffer targetBuffer)
        Deprecated.
        Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.
        Parameters:
        targetBuffer - The target buffer.
        Returns:
        The number of bytes added to the target buffer.
      • drain

        public int drain​(java.nio.ByteBuffer targetBuffer,
                         long maxDrained)
        Deprecated.
        Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.
        Parameters:
        targetBuffer - The target buffer.
        maxDrained - The maximum number of bytes drained by this call or 0 for unlimited length.
        Returns:
        The number of bytes added to the target buffer.
      • drain

        public BufferState drain​(java.lang.StringBuilder lineBuilder,
                                 BufferState builderState)
                          throws java.io.IOException
        Deprecated.
        Drains the buffer into a line builder (start line or header line).
        Parameters:
        lineBuilder - The line builder to fill.
        builderState - The builder state.
        Returns:
        The new builder state.
        Throws:
        java.io.IOException
      • drain

        public int drain​(java.nio.channels.WritableByteChannel wbc)
                  throws java.io.IOException
        Deprecated.
        Drains the byte buffer by attempting to write as much as possible on the given channel.
        Parameters:
        wbc - The byte channel to write to.
        Returns:
        The number of bytes written.
        Throws:
        java.io.IOException
      • fill

        public void fill​(byte[] sourceBuffer)
        Deprecated.
        Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.
        Parameters:
        sourceBuffer - The source buffer.
      • fill

        public int fill​(java.nio.ByteBuffer sourceBuffer)
        Deprecated.
        Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.
        Parameters:
        sourceBuffer - The source buffer.
        Returns:
        The number of bytes added from the source buffer.
      • fill

        public int fill​(java.nio.ByteBuffer sourceBuffer,
                        long maxFilled)
        Deprecated.
        Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.
        Parameters:
        sourceBuffer - The source buffer.
        maxFilled - The maximum number of bytes filled by this call or 0 for unlimited length.
        Returns:
        The number of bytes added from the source buffer.
      • fill

        public int fill​(java.nio.channels.ReadableByteChannel sourceChannel)
                 throws java.io.IOException
        Deprecated.
        Refills the byte buffer.
        Parameters:
        sourceChannel - The byte channel to read from.
        Returns:
        The number of bytes read and added or -1 if end of the source channel reached.
        Throws:
        java.io.IOException
      • fill

        public void fill​(java.lang.String source)
        Deprecated.
        Fills the byte buffer by copying as many bytes as possible from the source string, using the default platform encoding.
        Parameters:
        source - The source string.
      • flip

        public void flip()
        Deprecated.
        Flip from draining to filling or the other way around.
      • getBytes

        public java.nio.ByteBuffer getBytes()
        Deprecated.
        Returns the byte buffer.
        Returns:
        The byte buffer.
      • getLock

        public java.lang.Object getLock()
        Deprecated.
        Returns the lock on which multiple thread can synchronize to ensure safe access to the underlying byte buffer which isn't thread safe.
        Returns:
        The lock on which multiple thread can synchronize.
      • getState

        public BufferState getState()
        Deprecated.
        Returns the byte buffer IO state.
        Returns:
        The byte buffer IO state.
      • hasRemaining

        public final boolean hasRemaining()
        Deprecated.
        Indicates if the buffer has remaining bytes to be read or written.
        Returns:
        True if the buffer has remaining bytes to be read or written.
      • isEmpty

        public boolean isEmpty()
        Deprecated.
        Indicates if the buffer is empty in either filling or draining state.
        Returns:
        True if the buffer is empty.
      • process

        public int process​(BufferProcessor processor,
                           int maxDrained,
                           java.lang.Object... args)
                    throws java.io.IOException
        Deprecated.
        Processes as a loop the IO event by draining or filling the IO buffer. Note that synchronization of the getLock() object is automatically made.
        Parameters:
        processor - The IO processor to callback.
        maxDrained - The maximum number of bytes drained by this call or 0 for unlimited length.
        args - The optional arguments to pass back to the callbacks.
        Returns:
        The number of bytes drained or -1 if the filling source has ended.
        Throws:
        java.io.IOException
      • remaining

        public final int remaining()
        Deprecated.
        Returns the number of bytes that can be read or written in the byte buffer.
        Returns:
        The number of bytes that can be read or written.
      • setState

        public void setState​(BufferState byteBufferState)
        Deprecated.
        Sets the byte buffer IO state.
        Parameters:
        byteBufferState - The byte buffer IO state.
      • toString

        public java.lang.String toString()
        Deprecated.
        Overrides:
        toString in class java.lang.Object