net.sf.asyncobjects.io
Class BufferedInput<D extends BatchedData<D>,I extends AInput<D>>

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<I>
      extended by net.sf.asyncobjects.io.BufferedInput<D,I>
Type Parameters:
D - a batched data type
I - an input type
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing, AInput<D>
Direct Known Subclasses:
BufferedByteInput, BufferedTextInput

public class BufferedInput<D extends BatchedData<D>,I extends AInput<D>>
extends AsyncUnicastServer<I>
implements AInput<D>

A buffered input stream. Note that it reads at most toReadLimit bytes from underlying stream even if client asked for more.

The stream also supports prefetch mode (enabled by default). In this mode, when the buffer dries out, the stream initate a read request to the underlying stream. Therefore it is possible that buffer will replenish while client processes the data.

Author:
const

Constructor Summary
BufferedInput(I proxiedStream, int limit)
          A constructor from the stream
BufferedInput(I proxiedStream, int limit, boolean prefetch)
          A constructor from the stream
 
Method Summary
 Promise<Void> close()
          close stream
 Promise<Boolean> isPushbackSupported()
           
 Promise<Void> pushback(D pushbackData)
          Push data back to the stream
 Promise<D> read(int limit)
          read some bytes in buffer
 
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.AsyncObject
dereference, isImmediate
 

Constructor Detail

BufferedInput

public BufferedInput(I proxiedStream,
                     int limit,
                     boolean prefetch)
A constructor from the stream

Parameters:
proxiedStream - a stream that is being proxied
limit - a maximum amount of bites to be attempte to read from undelying stream
prefetch - if true the data is fetched when it is all read out before the next read operation false if data is fetched only during read requests.

BufferedInput

public BufferedInput(I proxiedStream,
                     int limit)
A constructor from the stream

Parameters:
proxiedStream - a stream that is being proxied
limit - a maximum amount of bites to be attempte to read from undelying stream
Method Detail

read

public Promise<D> read(int limit)
read some bytes in buffer

Specified by:
read in interface AInput<D extends BatchedData<D>>
Parameters:
limit - maximum amount of bytes that will be read by this operation
Returns:
read data or promise for it
See Also:
AInput.read(int)

pushback

public Promise<Void> pushback(D pushbackData)
Push data back to the stream

Specified by:
pushback in interface AInput<D extends BatchedData<D>>
Parameters:
pushbackData - a data that is being pushed back
Returns:
a promise that resolves to null or breaks with exception.
See Also:
AInput.pushback(BatchedData)

close

public Promise<Void> close()
close stream

Specified by:
close in interface ACloseable
Returns:
a promise that resolves to null or breaks with exception.

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()


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