Package org.simpleframework.transport
Class SocketBufferAppender
java.lang.Object
org.simpleframework.transport.SocketBufferAppender
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
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsConstructorDescriptionSocketBufferAppender
(Socket socket, int chunk, int limit) Constructor for theSocketBufferAppender
object. -
Method Summary
Modifier and TypeMethodDescriptionint
append
(ByteBuffer data) 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
capacity()
This represents the capacity of the backing store.encode()
This is used to encode the underlying byte sequence to text.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
length()
This is used to determine how mnay bytes remain within this buffer.int
space()
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.
-
Field Details
-
buffer
This is the buffer used to store the contents of the buffer. -
trace
This is the trace used to watch the buffering events. -
chunk
private int chunkThis represents the the initial size of the buffer to use. -
limit
private int limitThis represents the largest this appender can grow to.
-
-
Constructor Details
-
SocketBufferAppender
Constructor for theSocketBufferAppender
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 forchunk
- this is the initial size of the bufferlimit
- 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 whenspace
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
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
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
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 encodingsegment
- this is the buffer that is to be encoded- Returns:
- this returns the bytes sequence as a string object
- Throws:
IOException
-
append
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
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 bytescount
- this is the number of bytes that should be used- Returns:
- returns the number of bytes that have been moved
- Throws:
IOException
-
write
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 thelength
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
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 thelength
method. Once all of the bytes are written the buffer must be closed.- Parameters:
channel
- this is the channel to write the buffer tocount
- the number of bytes to write to the channel- Returns:
- this returns the number of bytes that were written
- Throws:
IOException
-
write
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 thelength
method. Once all of the bytes are written the buffer must be closed.- Parameters:
channel
- this is the channel to write the buffer tosegment
- this is the buffer that is to be written- Returns:
- this returns the number of bytes that were written
- Throws:
IOException
-