com.kuka.common
Class InbandBlobOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by com.kuka.common.InbandBlobOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class InbandBlobOutputStream
extends FilterOutputStream

Output stream that allows sending of binary large objects (BLOBs) over an existing output stream connection, such as the stream returned by Socket.getOutputStream().

This class encodes the transmission of the data in a stream of bytes that can be decoded by InbandBlobInputStream. The underlying stream will not be closed unless an error occurred while transmitting. The reason is that in this case we cannot be sure what part of the encoded data has been successfully transmitted.

The encoded data stream consists of:

  1. 4 bytes containing 0 if all data has been transmitted; otherwise the length of the following data stream as little-endian 32 bit integer (4 bytes)
  2. the announced amount of bytes of the BLOB data.
  3. continue with 1.


Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
InbandBlobOutputStream(OutputStream out, int windowSize)
          Creates a new instance of the stream filter.
 
Method Summary
 void close()
          Flushes the buffer and sends a end stream mark.
 void flush()
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InbandBlobOutputStream

public InbandBlobOutputStream(OutputStream out,
                              int windowSize)
Creates a new instance of the stream filter. Data written to this stream will be encoded as described in the class description and sent over the stream.

Parameters:
out - the underlying stream
windowSize - the size of the buffer. Data will be sent in windows of the buffer size.
Method Detail

write

public void write(int b)
           throws IOException
Overrides:
write in class FilterOutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class FilterOutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class FilterOutputStream
Throws:
IOException

close

public void close()
           throws IOException
Flushes the buffer and sends a end stream mark. Does NOT close the underlying stream that got passed in to the constructor, unless an IOException occurs.

Specified by:
close in interface Closeable
Overrides:
close in class FilterOutputStream
Throws:
IOException - if an I/O error occurs.


Copyright © 2019. All rights reserved.