net.sf.asyncobjects.io.util
Class SavingInput<D extends BatchedData<D>,I extends AInput<D>,O extends AOutput<D>>

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<FacetType>
      extended by net.sf.asyncobjects.util.CloseableWrapper<I,I>
          extended by net.sf.asyncobjects.io.util.SavingInput<D,I,O>
Type Parameters:
D - a batched data type
I - an input type
O - an output type
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing, AInput<D>
Direct Known Subclasses:
SavingByteInput, SavingTextInput

public class SavingInput<D extends BatchedData<D>,I extends AInput<D>,O extends AOutput<D>>
extends CloseableWrapper<I,I>
implements AInput<D>

This utility stream allows to save all data read from byte input to some output. It is useful for saving protocol of the session in file for further analysis during debugging. Note that output is never closed by this stream. The stream should be closed when allWritten() is smashed or resolved.

The stream support pushback(BatchedData) method if the underlying stream supports it. However the pushed back data is not saved. If pushback is detected, the stream ignores the next amount of bytes that has been pushed back if pushback operation was successful.

Author:
const

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.asyncobjects.util.CloseableWrapper
CloseableWrapper.InvalidatingWhen<I,R>
 
Field Summary
 
Fields inherited from class net.sf.asyncobjects.util.CloseableWrapper
closeWrapper, requests, wrapped
 
Constructor Summary
SavingInput(I in, boolean closeInput, O out)
          A constructor
 
Method Summary
 Promise<Void> allWritten()
           
 Promise<Boolean> isPushbackSupported()
           
 Promise<Void> pushback(D data)
          Pushbback some data
 Promise<D> read(int limit)
          In addition to stantad semantics.
 
Methods inherited from class net.sf.asyncobjects.util.CloseableWrapper
afterInvalidate, beforeClose, close, closed, ensureOpen, ensureValid, invalidate, isValid
 
Methods inherited from class net.sf.asyncobjects.AsyncUnicastServer
dereference, export, isImmediate, myVat, promise
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.asyncobjects.ACloseable
close
 
Methods inherited from interface net.sf.asyncobjects.AsyncObject
dereference, isImmediate
 

Constructor Detail

SavingInput

public SavingInput(I in,
                   boolean closeInput,
                   O out)
A constructor

Parameters:
in - an input to read
closeInput - if true input is closed on close operation
out - an output to write
Method Detail

read

public Promise<D> read(int limit)
In addition to stantad semantics. This method also saves all read data to output stream.

Specified by:
read in interface AInput<D extends BatchedData<D>>
Parameters:
limit - a maximum amount of data elements to read.
Returns:
Promise for non-empty data batch that contains read inforation or null if eof is reached.
See Also:
AInput.read(int)

allWritten

public Promise<Void> allWritten()
Returns:
a promise that resolves when all data has been read and sent to output. If there were errors during read or write operations, the promise is smashed with corresponding problem.

isPushbackSupported

public Promise<Boolean> isPushbackSupported()
Specified by:
isPushbackSupported in interface AInput<D extends BatchedData<D>>
Returns:
true if pushback supported for this stream
See Also:
AInput.isPushbackSupported()

pushback

public Promise<Void> pushback(D data)
Pushbback some data

Specified by:
pushback in interface AInput<D extends BatchedData<D>>
Parameters:
data - a data to push back
Returns:
when pushback finishes
See Also:
AInput.pushback(net.sf.asyncobjects.io.BatchedData)


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.