XNIO API 3.1.0.Beta1

org.xnio.streams
Class ChannelInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.xnio.streams.ChannelInputStream
All Implemented Interfaces:
Closeable

public class ChannelInputStream
extends InputStream

An input stream which reads from a stream source channel. All read operations are directly performed upon the channel, so for optimal performance, a buffering input stream should be used to wrap this class.

Since:
1.2

Field Summary
protected  StreamSourceChannel channel
           
protected  boolean closed
           
protected  long timeout
           
 
Constructor Summary
ChannelInputStream(StreamSourceChannel channel)
          Construct a new instance.
ChannelInputStream(StreamSourceChannel channel, long timeout, TimeUnit timeoutUnit)
          Construct a new instance.
 
Method Summary
 void close()
          
 long getReadTimeout(TimeUnit unit)
          Get the read timeout.
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 void setReadTimeout(long timeout, TimeUnit unit)
          Set the read timeout.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channel

protected final StreamSourceChannel channel

closed

protected volatile boolean closed

timeout

protected volatile long timeout
Constructor Detail

ChannelInputStream

public ChannelInputStream(StreamSourceChannel channel)
Construct a new instance. The stream will have no read timeout.

Parameters:
channel - the channel to wrap

ChannelInputStream

public ChannelInputStream(StreamSourceChannel channel,
                          long timeout,
                          TimeUnit timeoutUnit)
Construct a new instance.

Parameters:
channel - the channel to wrap
timeout - the read timeout, or O for none
timeoutUnit - the time unit for read timeouts
Method Detail

getReadTimeout

public long getReadTimeout(TimeUnit unit)
Get the read timeout.

Parameters:
unit - the time unit
Returns:
the timeout in the given unit

setReadTimeout

public void setReadTimeout(long timeout,
                           TimeUnit unit)
Set the read timeout. Does not affect read operations in progress.

Parameters:
timeout - the read timeout, or 0 for none
unit - the time unit

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

close

public void close()
           throws IOException

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

XNIO API 3.1.0.Beta1

Copyright © 2010 JBoss, a division of Red Hat, Inc.