public class ByteMessageTransfer extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_BUFFER_SIZE |
Constructor and Description |
---|
ByteMessageTransfer()
Create a new transfer setup to deal with messages of default maximum
size, which is 1024 bytes.
|
ByteMessageTransfer(int maxBufferSize)
Create a new transfer setup to deal with messages of specified maximum
size.
|
Modifier and Type | Method and Description |
---|---|
int |
getMaxBufferSize()
Get the current maximum buffer size supported by this byte transfer.
|
byte[] |
read(InputStream input)
Read length-prefixed data from the specified input stream and return a
newly allocated byte buffer that holds the data.
|
int |
readSOF(InputStream input)
Read and validate the length-prefixed start of frame from the specified
input stream and return the decoded length of the expected message.
|
void |
setMaxBufferSize(int maxBufferSize)
Set the current maximum buffer size supported by this byte transfer.
|
void |
write(OutputStream output,
byte[] data)
Write the given byte buffer to the specified output stream using the
length-prefixed transfer.
|
void |
write(OutputStream output,
byte[] data,
int offset,
int length)
Write the given section of a byte buffer to the specified output stream
using the length-prefixed transfer.
|
void |
write(OutputStream output,
Writable w)
Write the given writable to the specified output stream using the
length-prefixed transfer.
|
int |
writeSOF(OutputStream output,
int length)
Write a start of frame of the length-prefixed message.
|
public static final int DEFAULT_MAX_BUFFER_SIZE
public ByteMessageTransfer()
public ByteMessageTransfer(int maxBufferSize)
maxBufferSize
- maximum size of messages processed by this
transferpublic int getMaxBufferSize()
public void setMaxBufferSize(int maxBufferSize)
maxBufferSize
- maximum number of bytes allowed in a single
transferpublic void write(OutputStream output, byte[] data) throws IOException
output
- output stream to write todata
- byte buffer to writeIOException
- if issues encountered writing the messagepublic int writeSOF(OutputStream output, int length) throws IOException
output
- output stream to write tolength
- size of the message being writtenIOException
- if issues encountered writing the headerpublic void write(OutputStream output, byte[] data, int offset, int length) throws IOException
output
- output stream to write todata
- byte buffer to writeoffset
- offset at which to start the transferlength
- number of bytes to transferIOException
- if issues encountered writing the datapublic void write(OutputStream output, Writable w) throws IOException
output
- output stream to write tow
- writable object to writeIOException
- if issues encountered writing the messagepublic int readSOF(InputStream input) throws IOException
input
- input stream from which to readIOException
- if issues encountered reading the headerpublic byte[] read(InputStream input) throws IOException
input
- input stream from which to readIOException
- if issues encountered reading the messageCopyright © 2015. All Rights Reserved.