org.springframework.integration.ip.tcp.converter
Class ByteArrayLengthHeaderConverter
java.lang.Object
org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter
org.springframework.integration.ip.tcp.converter.ByteArrayLengthHeaderConverter
- All Implemented Interfaces:
- org.springframework.commons.serializer.InputStreamingConverter<byte[]>, org.springframework.commons.serializer.OutputStreamingConverter<byte[]>
public class ByteArrayLengthHeaderConverter
- extends AbstractByteArrayStreamingConverter
Converts data in an InputStream to a byte[]; data is preceded by
a 4 byte binary length (network byte order,
not included in resulting byte[]).
Writes a byte[] to an OutputStream after a 4 byte binary length.\
The length field contains the length of data following the length
field.
(network byte order).
- Author:
- Gary Russell
Method Summary |
void |
convert(byte[] bytes,
OutputStream outputStream)
Writes the byte[] to the output stream, preceded by a 4 byte
length in network byte order (big endian). |
byte[] |
convert(InputStream inputStream)
Reads a 4 byte length from the stream and then reads that length
from the stream and returns the data in a byte[]. |
protected int |
read(InputStream inputStream,
byte[] buffer,
boolean header)
Reads data from the socket and puts the data in buffer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ByteArrayLengthHeaderConverter
public ByteArrayLengthHeaderConverter()
convert
public byte[] convert(InputStream inputStream)
throws IOException
- Reads a 4 byte length from the stream and then reads that length
from the stream and returns the data in a byte[]. Throws an
IOException if the length field exceeds the maxMessageSize.
Throws a
SoftEndOfStreamException
if the stream
is closed between messages.
- Throws:
IOException
convert
public void convert(byte[] bytes,
OutputStream outputStream)
throws IOException
- Writes the byte[] to the output stream, preceded by a 4 byte
length in network byte order (big endian).
- Throws:
IOException
read
protected int read(InputStream inputStream,
byte[] buffer,
boolean header)
throws IOException
- Reads data from the socket and puts the data in buffer. Blocks until
buffer is full or a socket timeout occurs.
- Parameters:
buffer
- header
- true if we are reading the header
- Returns:
- < 0 if socket closed and not in the middle of a message
- Throws:
IOException
Copyright © 2010. All Rights Reserved.