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.
|
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(java.io.InputStream inputStream)
Reads the header from the stream and then reads the provided length
from the stream and returns the data in a byte[].
|
protected int |
read(java.io.InputStream inputStream,
byte[] buffer,
boolean header)
Reads data from the socket and puts the data in buffer.
|
protected int |
readHeader(java.io.InputStream inputStream)
Reads the header and returns the length of the data part.
|
void |
serialize(byte[] bytes,
java.io.OutputStream outputStream)
Writes the byte[] to the output stream, preceded by a 4 byte
length in network byte order (big endian).
|
protected void |
writeHeader(java.io.OutputStream outputStream,
int length)
Writes the header, according to the header format.
|
checkClosure, copyToSizedArray, getMaxMessageSize, setMaxMessageSize
public static final int HEADER_SIZE_INT
public static final int HEADER_SIZE_UNSIGNED_BYTE
public static final int HEADER_SIZE_UNSIGNED_SHORT
public ByteArrayLengthHeaderSerializer()
HEADER_SIZE_INT
public ByteArrayLengthHeaderSerializer(int headerSize)
HEADER_SIZE_INT
(default),
HEADER_SIZE_UNSIGNED_BYTE
and HEADER_SIZE_UNSIGNED_SHORT
headerSize
- public byte[] deserialize(java.io.InputStream inputStream) throws java.io.IOException
SoftEndOfStreamException
if the stream
is closed between messages.java.io.IOException
public void serialize(byte[] bytes, java.io.OutputStream outputStream) throws java.io.IOException
java.io.IOException
protected int read(java.io.InputStream inputStream, byte[] buffer, boolean header) throws java.io.IOException
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 messagejava.io.IOException
protected void writeHeader(java.io.OutputStream outputStream, int length) throws java.io.IOException
outputStream
- length
- java.io.IOException
protected int readHeader(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- java.io.IOException
SoftEndOfStreamException
- if socket closes
before any length data read.