org.ow2.petals.transport.platform.nio.util.stream.queue
Class QueueOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.ow2.petals.transport.platform.nio.util.stream.queue.QueueOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class QueueOutputStream
extends java.io.OutputStream

This class implements an output stream in which the data are written into a byte array queue. Each write creates a new entry in the queue. The new entry is a copy of the buffer to write.

This class is thread-safe, and should be used with QueueInputStream.

Closing a QueueOutputStream has no effect. For performance reasons (no check is done), the methods in this class can be called after the stream has been closed without generating an IOException.

Author:
Christophe DENEUX - Capgemini Sud

Field Summary
protected  java.util.Queue<byte[]> bufferList
           
 
Constructor Summary
QueueOutputStream()
           
 
Method Summary
 void write(byte[] b, int off, int len)
           Writes len bytes from the specified byte array starting at offset off to this byte array queue output stream.
 void write(int b)
          Writes the specified byte to this byte array linked list output stream.
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferList

protected final java.util.Queue<byte[]> bufferList
Constructor Detail

QueueOutputStream

public QueueOutputStream()
Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this byte array linked list output stream.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte to be written.
Throws:
java.io.IOException
See Also:
OutputStream#write(int)}

write

public void write(byte[] b,
                  int off,
                  int len)

Writes len bytes from the specified byte array starting at offset off to this byte array queue output stream.

Note:

  1. this method is overriden to increase performance (we create only one buffer in the queue, instead of one per byte),
  2. if the provided buffer must be completely written ( off == 0 && len == b.length), it is added by reference in the queue,
  3. if the provided buffer must be partially written, the part to write is cloned.

Overrides:
write in class java.io.OutputStream
Parameters:
b - the data buffer to writer.
off - the start offset in the data.
len - the number of bytes to write.


Copyright © 2005-2011 Petals Link (EBM Websourcing). All Rights Reserved.