org.knime.core.data.container
Class BlockableOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.knime.core.data.container.BlockableOutputStream
All Implemented Interfaces:
Closeable, Flushable, KNIMEStreamConstants

final class BlockableOutputStream
extends OutputStream
implements KNIMEStreamConstants

Output stream that allows to set block marks. It will scan the byte array on incoming write(byte[]) or write(byte[], int, int) invocations and escape the bytes if necessary.

This class is used to mark the end of a DataCell in order avoid stream corruption when a DataCell reads more (or less) than it has written.

Author:
Bernd Wiswedel, University of Konstanz

Field Summary
 
Fields inherited from interface org.knime.core.data.container.KNIMEStreamConstants
BYTE_ROW_SEPARATOR, BYTE_TYPE_MISSING, BYTE_TYPE_SERIALIZATION, BYTE_TYPE_START, DUMMY_ROW_KEY, TC_ESCAPE, TC_TERMINATE
 
Constructor Summary
BlockableOutputStream(OutputStream outStream)
          Constructor that simply memorizes the stream to write to.
 
Method Summary
 void close()
          Delegates to output stream.
 void endBlock()
          Writes a terminate character to the underlying stream.
 void flush()
          Delegates to output stream.
 void write(byte[] b)
          Calls write(byte[], int, int).
 void write(byte[] b, int off, int len)
          Parses the byte[] argument, escapes the bytes if necessary and delegates escaped byte array to underlying stream.
 void write(int b)
          Checks if the byte to be written needs to be escaped and does so if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockableOutputStream

BlockableOutputStream(OutputStream outStream)
Constructor that simply memorizes the stream to write to.

Parameters:
outStream - to write to, never null
Method Detail

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Parses the byte[] argument, escapes the bytes if necessary and delegates escaped byte array to underlying stream.

Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Calls write(byte[], int, int).

Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Checks if the byte to be written needs to be escaped and does so if necessary.

Specified by:
write in class OutputStream
Throws:
IOException

close

public void close()
           throws IOException
Delegates to output stream.

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Delegates to output stream.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

endBlock

public void endBlock()
              throws IOException
Writes a terminate character to the underlying stream.

Throws:
IOException - if the write fails


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.