Spring Integration

org.springframework.integration.ip.tcp.converter
Class ByteArrayLengthHeaderConverter

java.lang.Object
  extended by org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter
      extended by org.springframework.integration.ip.tcp.converter.ByteArrayLengthHeaderConverter
All Implemented Interfaces:
InputStreamingConverter<byte[]>, 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

Field Summary
 
Fields inherited from class org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter
maxMessageSize
 
Constructor Summary
ByteArrayLengthHeaderConverter()
           
 
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 org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter
checkClosure, getMaxMessageSize, setMaxMessageSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayLengthHeaderConverter

public ByteArrayLengthHeaderConverter()
Method Detail

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.

Parameters:
inputStream - The InputStream.
Returns:
The object.
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).

Parameters:
bytes - The object.
outputStream - The outputStream.
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

Spring Integration

Copyright © 2010. All Rights Reserved.