@XmlHints(allowTopLevelDefinition=true) public class LengthProtocol extends DirectProtocol
TcpProtocol that can be used to transfer large amounts of data without risking
some data to be loss. The protocol is defined by sending / reading an integer (the packet length) and then the data to be
transferred.
Note that use of this protocol must be symmetric - both the sending and receiving connectors must use the same protocol.
| Modifier and Type | Field and Description |
|---|---|
static String |
LENGTH_EXCEEDED |
bufferSize, UNLIMITEDEOF, NO_MAX_LENGTH, NO_STREAM, objectSerializer, rethrowExceptionOnRead, STREAM_OK, streamOk| Constructor and Description |
|---|
LengthProtocol() |
LengthProtocol(int maxMessageLength) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isRepeat(int len,
int available)
Read all four bytes for initial integer (limit is set in read)
|
InputStream |
read(InputStream socketIs)
It consumes the socket
InputStream according to this#consume(InputStream) and then wraps the result into a
ByteArrayInputStream. |
protected void |
writeByteArray(OutputStream outputStream,
byte[] data)
It first writes the an int representing the length of the data to be written, and then writes the actual data.
|
consume, remaining, writecopy, copy, nullIfEmptyArray, safeRead, safeRead, setObjectSerializerpublic static final String LENGTH_EXCEEDED
public LengthProtocol()
public LengthProtocol(int maxMessageLength)
public InputStream read(InputStream socketIs) throws IOException
InputStream according to this#consume(InputStream) and then wraps the result into a
ByteArrayInputStream.read in interface TcpProtocolread in class DirectProtocolsocketIs - null if this#consume(InputStream) throws an IOException and rethrowExceptionOnRead is
not setIOException - is thrown if rethrowExceptionOnRead is setprotected void writeByteArray(OutputStream outputStream, byte[] data) throws IOException
writeByteArray in class AbstractByteProtocoloutputStream - in which the data will be writtendata - to be writtenLengthExceededException - if the length of the message to be written exceeds the maxMessageLength setIOExceptionprotected boolean isRepeat(int len,
int available)
isRepeat in class DirectProtocollen - Amount transferred last call (-1 on EOF or socket error)available - Amount availableCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.