Top Description Fields Constructors Methods
org.xnio.streams

public Class BufferedChannelInputStream

extends InputStream
Class Inheritance
Imports
java.io.InputStream, .IOException, .InterruptedIOException, java.nio.ByteBuffer, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, org.xnio.Bits, .Buffers, org.xnio.channels.Channels, .StreamSourceChannel

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

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final StreamSourceChannel
private static final int
private static final int
private volatile int
private static final AtomicIntegerFieldUpdater<BufferedChannelInputStream>
private volatile long

Constructor Summary

AccessConstructor and Description
public
BufferedChannelInputStream(final StreamSourceChannel
the channel to wrap
channel
,
final int
the size of the internal buffer
bufferSize
)

Construct a new instance.

public
BufferedChannelInputStream(final StreamSourceChannel
the channel to wrap
channel
,
final int
the size of the internal buffer
bufferSize
,
final long
the initial read timeout, or O for none
timeout
,
final TimeUnit
the time unit for the read timeout
unit
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of ready bytes, or 0 for none
available
()

Overrides java.io.InputStream.available.

Return the number of bytes available to read, or 0 if a subsequent read() operation would block.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream.

private boolean
private void
exit(boolean setEof)

public long

Returns:

the timeout in the given unit
getReadTimeout
(TimeUnit
the time unit
unit
)

Get the read timeout.

public int

Returns:

the byte read, or -1 if the end of the stream has been reached
read
()

Implements abstract java.io.InputStream.read.

Read a byte, blocking if necessary.

public int

Returns:

the number of bytes read, or -1 if the end of the stream has been reached
read
(final byte[]
the destination array
b
,
int
the offset into the array at which bytes should be filled
off
,
int
the number of bytes to fill
len
)

Overrides java.io.InputStream.read.

Read bytes into an array.

public void
setReadTimeout(long
the read timeout, or 0 for none
timeout
,
TimeUnit
the time unit
unit
)

Set the read timeout.

public long

Returns:

the number of bytes skipped (0 if the end of stream has been reached)
skip
(long
the number of bytes to skip
n
)

Overrides java.io.InputStream.skip.

Skip bytes in the stream.

Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipNBytestransferTo

Field Detail

bufferback to summary
private final ByteBuffer buffer
channelback to summary
private final StreamSourceChannel channel
FLAG_ENTEREDback to summary
private static final int FLAG_ENTERED
FLAG_EOFback to summary
private static final int FLAG_EOF
flagsback to summary
private volatile int flags
Annotations
@SuppressWarnings:unused
flagsUpdaterback to summary
private static final AtomicIntegerFieldUpdater<BufferedChannelInputStream> flagsUpdater
timeoutback to summary
private volatile long timeout

Constructor Detail

BufferedChannelInputStreamback to summary
public BufferedChannelInputStream(final StreamSourceChannel channel, final int bufferSize)

Construct a new instance.

Parameters
channel:StreamSourceChannel

the channel to wrap

bufferSize:int

the size of the internal buffer

BufferedChannelInputStreamback to summary
public BufferedChannelInputStream(final StreamSourceChannel channel, final int bufferSize, final long timeout, final TimeUnit unit)

Construct a new instance.

Parameters
channel:StreamSourceChannel

the channel to wrap

bufferSize:int

the size of the internal buffer

timeout:long

the initial read timeout, or O for none

unit:TimeUnit

the time unit for the read timeout

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

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.

Returns:int

the number of ready bytes, or 0 for none

Exceptions
IOException:
if an I/O error occurs
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Close the stream. Shuts down the channel's read side.

Exceptions
IOException:
if an I/O error occurs
enterback to summary
private boolean enter()
exitback to summary
private void exit(boolean setEof)
getReadTimeoutback to summary
public long getReadTimeout(TimeUnit unit)

Get the read timeout.

Parameters
unit:TimeUnit

the time unit

Returns:long

the timeout in the given unit

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Read a byte, blocking if necessary.

Returns:int

the byte read, or -1 if the end of the stream has been reached

Exceptions
IOException:
if an I/O error occurs
readback to summary
public int read(final byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Read bytes into an array.

Parameters
b:byte[]

the destination array

off:int

the offset into the array at which bytes should be filled

len:int

the number of bytes to fill

Returns:int

the number of bytes read, or -1 if the end of the stream has been reached

Exceptions
IOException:
if an I/O error occurs
setReadTimeoutback to summary
public void setReadTimeout(long timeout, TimeUnit unit)

Set the read timeout. Does not affect read operations in progress.

Parameters
timeout:long

the read timeout, or 0 for none

unit:TimeUnit

the time unit

skipback to summary
public long skip(long n) throws IOException

Overrides java.io.InputStream.skip.

Skip bytes in the stream.

Parameters
n:long

the number of bytes to skip

Returns:long

the number of bytes skipped (0 if the end of stream has been reached)

Exceptions
IOException:
if an I/O error occurs