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, maxMessageSize| Constructor and Description |
|---|
ByteArrayLengthHeaderSerializer()
Constructs the serializer using
HEADER_SIZE_INT |
ByteArrayLengthHeaderSerializer(int headerSize)
Constructs the serializer using the supplied header size.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
deserialize(InputStream inputStream)
Reads 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 lenght header value includes its own length.
|
protected int |
read(InputStream inputStream,
byte[] buffer,
boolean header)
Reads data from the socket and puts the data in buffer.
|
protected int |
readHeader(InputStream inputStream)
Reads the header and returns the length of the data part.
|
void |
serialize(byte[] bytes,
OutputStream outputStream)
Writes 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)
Writes the header, according to the header format.
|
checkClosure, getMaxMessageSize, publishEvent, setApplicationEventPublisher, setMaxMessageSizepublic 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_INTpublic ByteArrayLengthHeaderSerializer(int headerSize)
HEADER_SIZE_INT (default),
HEADER_SIZE_UNSIGNED_BYTE and HEADER_SIZE_UNSIGNED_SHORTheaderSize - 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.IOExceptionprotected 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.