public class ByteArrayLengthHeaderSerializer extends AbstractByteArraySerializer
readHeader(InputStream)
and
writeHeader(OutputStream, int)
.Modifier and Type | Field and Description |
---|---|
static int |
HEADER_SIZE_INT
Default length-header field, allows for data up to 2**31-1 bytes.
|
static int |
HEADER_SIZE_UNSIGNED_BYTE
A single unsigned byte, for data up to 255 bytes.
|
static int |
HEADER_SIZE_UNSIGNED_SHORT
An unsigned short, for data up to 2**16 bytes.
|
DEFAULT_MAX_MESSAGE_SIZE, logger
Constructor and Description |
---|
ByteArrayLengthHeaderSerializer()
Construct the serializer using
HEADER_SIZE_INT |
ByteArrayLengthHeaderSerializer(int headerSize)
Construct the serializer using the supplied header size.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
deserialize(InputStream inputStream)
Read the header from the stream and then reads the provided length
from the stream and returns the data in a byte[].
|
ByteArrayLengthHeaderSerializer |
inclusive()
Include the length of the header in addition to the payload.
|
protected boolean |
isInclusive()
Return true if the length header value includes its own length.
|
protected int |
read(InputStream inputStream,
byte[] buffer,
boolean header)
Read data from the socket and puts the data in buffer.
|
protected int |
readHeader(InputStream inputStream)
Read the header and returns the length of the data part.
|
void |
serialize(byte[] bytes,
OutputStream outputStream)
Write the byte[] to the output stream, preceded by a 4 byte
length in network byte order (big endian).
|
void |
setInclusive(boolean inclusive)
Set to true to set the length header to include the length of the header in
addition to the payload.
|
protected void |
writeHeader(OutputStream outputStream,
int length)
Write the header, according to the header format.
|
checkClosure, getMaxMessageSize, publishEvent, setApplicationEventPublisher, setMaxMessageSize
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
serializeToByteArray
deserializeFromByteArray
public static final int HEADER_SIZE_INT
public static final int HEADER_SIZE_UNSIGNED_SHORT
public static final int HEADER_SIZE_UNSIGNED_BYTE
public ByteArrayLengthHeaderSerializer()
HEADER_SIZE_INT
public ByteArrayLengthHeaderSerializer(int headerSize)
HEADER_SIZE_INT
(default),
HEADER_SIZE_UNSIGNED_BYTE
and HEADER_SIZE_UNSIGNED_SHORT
headerSize
- The header size.protected boolean isInclusive()
public void setInclusive(boolean inclusive)
HEADER_SIZE_INT
(default),
HEADER_SIZE_UNSIGNED_BYTE
and HEADER_SIZE_UNSIGNED_SHORT
and 4, 1
and 2 will be added to the payload length respectively.inclusive
- true to include the header length.inclusive()
public ByteArrayLengthHeaderSerializer inclusive()
HEADER_SIZE_INT
(default), HEADER_SIZE_UNSIGNED_BYTE
and
HEADER_SIZE_UNSIGNED_SHORT
and 4, 1 and 2 will be added to the payload
length respectively. Fluent API form of setInclusive(boolean)
.setInclusive(boolean)
public byte[] deserialize(InputStream inputStream) throws IOException
SoftEndOfStreamException
if the stream
is closed between messages.inputStream
- The input stream.IOException
- Any IOException.public void serialize(byte[] bytes, OutputStream outputStream) throws IOException
bytes
- The bytes.outputStream
- The output stream.IOException
protected int read(InputStream inputStream, byte[] buffer, boolean header) throws IOException
inputStream
- The input stream.buffer
- the buffer into which the data should be readheader
- true if we are reading the header< 0
if socket closed and not in the middle of a messageIOException
- Any IOException.protected void writeHeader(OutputStream outputStream, int length) throws IOException
outputStream
- The output stream.length
- The length.IOException
- Any IOException.protected int readHeader(InputStream inputStream) throws IOException
inputStream
- The input stream.IOException
- Any IOException.SoftEndOfStreamException
- if socket closes
before any length data read.