Class SocketBufferAppender

java.lang.Object
org.simpleframework.transport.SocketBufferAppender

class SocketBufferAppender extends Object
The SocketBufferAppender represents a buffer fragment collector. This provides write access to a direct byte buffer which is used to collect fragments. Once a sufficient amount of data has been collected by this then can be written out to a channel.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private ByteBuffer
    This is the buffer used to store the contents of the buffer.
    private int
    This represents the the initial size of the buffer to use.
    private int
    This represents the largest this appender can grow to.
    private Trace
    This is the trace used to watch the buffering events.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SocketBufferAppender(Socket socket, int chunk, int limit)
    Constructor for the SocketBufferAppender object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    This will append bytes within the given buffer to the buffer.
    int
    append(ByteBuffer data, int count)
    This will append bytes within the given buffer to the buffer.
    int
    This represents the capacity of the backing store.
    This is used to encode the underlying byte sequence to text.
    encode(String encoding)
    This is used to encode the underlying byte sequence to text.
    private String
    encode(String encoding, ByteBuffer segment)
    This is used to encode the underlying byte sequence to text.
    int
    This is used to determine how mnay bytes remain within this buffer.
    int
    This is used to determine how much space is left to append data to this buffer.
    int
    write(ByteChannel channel)
    This write method will write the contents of the buffer to the provided byte channel.
    int
    write(ByteChannel channel, int count)
    This write method will write the contents of the buffer to the provided byte channel.
    private int
    write(ByteChannel channel, ByteBuffer segment)
    This write method will write the contents of the buffer to the provided byte channel.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • buffer

      private ByteBuffer buffer
      This is the buffer used to store the contents of the buffer.
    • trace

      private Trace trace
      This is the trace used to watch the buffering events.
    • chunk

      private int chunk
      This represents the the initial size of the buffer to use.
    • limit

      private int limit
      This represents the largest this appender can grow to.
  • Constructor Details

    • SocketBufferAppender

      public SocketBufferAppender(Socket socket, int chunk, int limit)
      Constructor for the SocketBufferAppender object. This is used to create an appender that can collect smaller fragments in to a larger buffer so that it can be delivered more efficiently.
      Parameters:
      socket - this is the socket to append data for
      chunk - this is the initial size of the buffer
      limit - this is the maximum size of the buffer
  • Method Details

    • space

      public int space()
      This is used to determine how much space is left to append data to this buffer. This is typically equivalent to capacity minus the length. However in the event that the buffer uses a private memory store that can not be written to then this can return zero regardless of the capacity and length.
      Returns:
      the space left within the buffer to append data to
    • capacity

      public int capacity()
      This represents the capacity of the backing store. The buffer is full when length is equal to capacity and it can typically be appended to when the length is less than the capacity. The only exception is when space returns zero, which means that the buffer can not have bytes appended to it.
      Returns:
      this is the capacity of other backing byte storage
    • length

      public int length()
      This is used to determine how mnay bytes remain within this buffer. It represents the number of write ready bytes, so if the length is greater than zero the buffer can be written to a byte channel. When length is zero the buffer can be closed.
      Returns:
      this is the number of bytes remaining in this buffer
    • encode

      public String encode() throws IOException
      This is used to encode the underlying byte sequence to text. Converting the byte sequence to text can be useful when either debugging what exactly is being sent. Also, for transports that require string delivery of buffers this can be used.
      Returns:
      this returns the bytes sequence as a string object
      Throws:
      IOException
    • encode

      public String encode(String encoding) throws IOException
      This is used to encode the underlying byte sequence to text. Converting the byte sequence to text can be useful when either debugging what exactly is being sent. Also, for transports that require string delivery of buffers this can be used.
      Parameters:
      encoding - this is the character set to use for encoding
      Returns:
      this returns the bytes sequence as a string object
      Throws:
      IOException
    • encode

      private String encode(String encoding, ByteBuffer segment) throws IOException
      This is used to encode the underlying byte sequence to text. Converting the byte sequence to text can be useful when either debugging what exactly is being sent. Also, for transports that require string delivery of buffers this can be used.
      Parameters:
      encoding - this is the character set to use for encoding
      segment - this is the buffer that is to be encoded
      Returns:
      this returns the bytes sequence as a string object
      Throws:
      IOException
    • append

      public int append(ByteBuffer data) throws IOException
      This will append bytes within the given buffer to the buffer. Once invoked the buffer will contain the buffer bytes, which will have been drained from the buffer. This effectively moves the bytes in the buffer to the end of the buffer instance.
      Parameters:
      data - this is the buffer containing the bytes
      Returns:
      returns the number of bytes that have been moved
      Throws:
      IOException
    • append

      public int append(ByteBuffer data, int count) throws IOException
      This will append bytes within the given buffer to the buffer. Once invoked the buffer will contain the buffer bytes, which will have been drained from the buffer. This effectively moves the bytes in the buffer to the end of the buffer instance.
      Parameters:
      data - this is the buffer containing the bytes
      count - this is the number of bytes that should be used
      Returns:
      returns the number of bytes that have been moved
      Throws:
      IOException
    • write

      public int write(ByteChannel channel) throws IOException
      This write method will write the contents of the buffer to the provided byte channel. If the whole buffer can be be written then this will simply return the number of bytes that have. The number of bytes remaining within the buffer after a write can be acquired from the length method. Once all of the bytes are written the buffer must be closed.
      Parameters:
      channel - this is the channel to write the buffer to
      Returns:
      this returns the number of bytes that were written
      Throws:
      IOException
    • write

      public int write(ByteChannel channel, int count) throws IOException
      This write method will write the contents of the buffer to the provided byte channel. If the whole buffer can be be written then this will simply return the number of bytes that have. The number of bytes remaining within the buffer after a write can be acquired from the length method. Once all of the bytes are written the buffer must be closed.
      Parameters:
      channel - this is the channel to write the buffer to
      count - the number of bytes to write to the channel
      Returns:
      this returns the number of bytes that were written
      Throws:
      IOException
    • write

      private int write(ByteChannel channel, ByteBuffer segment) throws IOException
      This write method will write the contents of the buffer to the provided byte channel. If the whole buffer can be be written then this will simply return the number of bytes that have. The number of bytes remaining within the buffer after a write can be acquired from the length method. Once all of the bytes are written the buffer must be closed.
      Parameters:
      channel - this is the channel to write the buffer to
      segment - this is the buffer that is to be written
      Returns:
      this returns the number of bytes that were written
      Throws:
      IOException