net.i2p.client.streaming
Class MessageOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by net.i2p.client.streaming.MessageOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class MessageOutputStream
extends OutputStream

A stream that we can shove data into that fires off those bytes on flush or when the buffer is full. It also blocks according to the data receiver's needs.


Nested Class Summary
static interface MessageOutputStream.DataReceiver
          Define a component to receive data flushed from this stream
static interface MessageOutputStream.WriteStatus
          Define a way to detect the status of a write
 
Constructor Summary
MessageOutputStream(I2PAppContext ctx, MessageOutputStream.DataReceiver receiver)
           
MessageOutputStream(I2PAppContext ctx, MessageOutputStream.DataReceiver receiver, int bufSize)
           
MessageOutputStream(I2PAppContext ctx, MessageOutputStream.DataReceiver receiver, int bufSize, int passiveFlushDelay)
           
 
Method Summary
 void close()
          This does a flush, and BLOCKS until the CLOSE packet is acked.
 void closeInternal()
          nonblocking close - Use outside of this package is deprecated, should be made package local
(package private)  void destroy()
           
 void flush()
          Flush the data already queued up, blocking only if the outbound window is full.
(package private)  void flushAvailable(MessageOutputStream.DataReceiver target)
          called whenever the engine wants to push more data to the peer
(package private)  void flushAvailable(MessageOutputStream.DataReceiver target, boolean blocking)
           
 boolean getClosed()
           
 int getWriteTimeout()
           
 void setBufferSize(int size)
           
 void setWriteTimeout(int ms)
           
(package private)  void streamErrorOccurred(IOException ioe)
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageOutputStream

public MessageOutputStream(I2PAppContext ctx,
                           MessageOutputStream.DataReceiver receiver)

MessageOutputStream

public MessageOutputStream(I2PAppContext ctx,
                           MessageOutputStream.DataReceiver receiver,
                           int bufSize)

MessageOutputStream

public MessageOutputStream(I2PAppContext ctx,
                           MessageOutputStream.DataReceiver receiver,
                           int bufSize,
                           int passiveFlushDelay)
Method Detail

setWriteTimeout

public void setWriteTimeout(int ms)

getWriteTimeout

public int getWriteTimeout()

setBufferSize

public void setBufferSize(int size)

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

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

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Flush the data already queued up, blocking only if the outbound window is full. Prior to 0.8.1, this blocked until "delivered". "Delivered" meant "received an ACK from the far end", which is not the commom implementation of flush(), and really hurt the performance of i2psnark, which flush()ed frequently. Calling flush() would cause a complete window stall. As of 0.8.1, only wait for accept into the streaming output queue. This will speed up snark significantly, and allow us to flush() the initial data in I2PTunnelRunner, saving 250 ms.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException - if the write fails

close

public void close()
           throws IOException
This does a flush, and BLOCKS until the CLOSE packet is acked.

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

closeInternal

public void closeInternal()
nonblocking close - Use outside of this package is deprecated, should be made package local


getClosed

public boolean getClosed()

streamErrorOccurred

void streamErrorOccurred(IOException ioe)

flushAvailable

void flushAvailable(MessageOutputStream.DataReceiver target)
              throws IOException
called whenever the engine wants to push more data to the peer

Throws:
IOException

flushAvailable

void flushAvailable(MessageOutputStream.DataReceiver target,
                    boolean blocking)
              throws IOException
Throws:
IOException

destroy

void destroy()