net.metanotion.util
Interface Pump<D>


public interface Pump<D>

A Pump connects an InputStream like object to an OutputStream like object. Not every "stream" like object can reliably indicate whether they will block, but this should provide enough options to be useful. The generic type indicates what type of data is flowing through the pump. Possible future versions of this interface may support timed and timeout conditions.


Method Summary
 boolean isClosed()
          Determine whether the end of the stream has been encountered.
 void pumpAll()
          Completely transfer the input to the output until an "End of Stream" indication occurs.
 int pumpCount(int n)
          Transfer up to n items from input to output.
 int pumpCountUntilBlocked(int n)
          Transfer up to n items from input to output, stopping for end-of-stream OR potentially blockage.
 void pumpUntilBlocked()
          Transfer the input to the output until a blocking condition is detected, and then return control.
 

Method Detail

pumpAll

void pumpAll()
Completely transfer the input to the output until an "End of Stream" indication occurs.


pumpUntilBlocked

void pumpUntilBlocked()
Transfer the input to the output until a blocking condition is detected, and then return control. In the event that a stream does not support the notion of detecting a blocking condition this method should behave like pumpAll. This method MAY block anyway, if an undetectable event that would entail blocking occurs.


pumpCount

int pumpCount(int n)
Transfer up to n items from input to output.

Parameters:
n - The maximum number of items to transfer.
Returns:
The number of items actually transferred(Indicates end-of-stream if less than n).

pumpCountUntilBlocked

int pumpCountUntilBlocked(int n)
Transfer up to n items from input to output, stopping for end-of-stream OR potentially blockage. In the event a stream does not support the ability to detect blockage, the semantics of this call are equivalent to pumpCount(n).

Parameters:
n - The maximum number of items to transfer.
Returns:
The number of items actually transferred(Indicates end-of-stream or blockage if less than n).

isClosed

boolean isClosed()
Determine whether the end of the stream has been encountered.

Returns:
true if an End of Stream event has occurred, false otherwise.