XNIO API 3.0.4.GA

org.xnio.streams
Class BufferedChannelInputStream

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

public class BufferedChannelInputStream
extends InputStream

An input stream which reads from a stream source channel with a buffer. In addition, the available() method can be used to determine whether the next read will or will not block.

Since:
2.1

Constructor Summary
BufferedChannelInputStream(StreamSourceChannel channel, int bufferSize)
          Construct a new instance.
BufferedChannelInputStream(StreamSourceChannel channel, int bufferSize, long timeout, TimeUnit unit)
          Construct a new instance.
 
Method Summary
 int available()
          Return the number of bytes available to read, or 0 if a subsequent read() operation would block.
 void close()
          Close the stream.
 long getReadTimeout(TimeUnit unit)
          Get the read timeout.
 int read()
          Read a byte, blocking if necessary.
 int read(byte[] b, int off, int len)
          Read bytes into an array.
 void setReadTimeout(long timeout, TimeUnit unit)
          Set the read timeout.
 long skip(long n)
          Skip bytes in the stream.
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedChannelInputStream

public BufferedChannelInputStream(StreamSourceChannel channel,
                                  int bufferSize)
Construct a new instance.

Parameters:
channel - the channel to wrap
bufferSize - the size of the internal buffer

BufferedChannelInputStream

public BufferedChannelInputStream(StreamSourceChannel channel,
                                  int bufferSize,
                                  long timeout,
                                  TimeUnit unit)
Construct a new instance.

Parameters:
channel - the channel to wrap
bufferSize - the size of the internal buffer
timeout - the initial read timeout, or O for none
unit - the time unit for the read timeout
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
Read a byte, blocking if necessary.

Specified by:
read in class InputStream
Returns:
the byte read, or -1 if the end of the stream has been reached
Throws:
IOException - if an I/O error occurs

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Read bytes into an array.

Overrides:
read in class InputStream
Parameters:
b - the destination array
off - the offset into the array at which bytes should be filled
len - the number of bytes to fill
Returns:
the number of bytes read, or -1 if the end of the stream has been reached
Throws:
IOException - if an I/O error occurs

skip

public long skip(long n)
          throws IOException
Skip bytes in the stream.

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to skip
Returns:
the number of bytes skipped (0 if the end of stream has been reached)
Throws:
IOException - if an I/O error occurs

available

public int available()
              throws IOException
Return the number of bytes available to read, or 0 if a subsequent read() operation would block. If a 0 is returned, the channel's resumeReads() method may be used to register for read-readiness.

Overrides:
available in class InputStream
Returns:
the number of ready bytes, or 0 for none
Throws:
IOException - if an I/O error occurs

close

public void close()
           throws IOException
Close the stream. Shuts down the channel's read side.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - if an I/O error occurs

XNIO API 3.0.4.GA

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