public class BlockingByteChannel
extends java.lang.Object
implements java.nio.channels.ScatteringByteChannel, java.nio.channels.GatheringByteChannel, java.nio.channels.ByteChannel, java.io.Flushable
StreamChannel
. Read and write operations will block until some data may be transferred.
Once any amount of data is read or written, the operation will return. If a read timeout is specified, then the read methods
will throw a ReadTimeoutException
if the timeout expires without reading any data. If a write timeout is specified, then the write methods
will throw a WriteTimeoutException
if the timeout expires without writing any data.Constructor and Description |
---|
BlockingByteChannel(StreamChannel delegate)
Construct a new instance.
|
BlockingByteChannel(StreamChannel delegate,
long timeout,
java.util.concurrent.TimeUnit timeoutUnit)
Construct a new instance.
|
BlockingByteChannel(StreamChannel delegate,
long readTimeout,
java.util.concurrent.TimeUnit readTimeoutUnit,
long writeTimeout,
java.util.concurrent.TimeUnit writeTimeoutUnit)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
boolean |
isOpen() |
int |
read(java.nio.ByteBuffer dst)
Perform a blocking read operation.
|
long |
read(java.nio.ByteBuffer[] dsts)
Perform a blocking, scattering read operation.
|
long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length)
Perform a blocking, scattering read operation.
|
void |
setReadTimeout(long readTimeout,
java.util.concurrent.TimeUnit readTimeoutUnit)
Set the read timeout.
|
void |
setWriteTimeout(long writeTimeout,
java.util.concurrent.TimeUnit writeTimeoutUnit)
Set the write timeout.
|
int |
write(java.nio.ByteBuffer src)
Perform a blocking write operation.
|
long |
write(java.nio.ByteBuffer[] srcs)
Perform a blocking, gathering write operation.
|
long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length)
Perform a blocking, gathering write operation.
|
public BlockingByteChannel(StreamChannel delegate)
delegate
- the channel to forward I/O operations topublic BlockingByteChannel(StreamChannel delegate, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
delegate
- the channel to forward I/O operations totimeout
- the read/write timeouttimeoutUnit
- the read/write timeout unitpublic BlockingByteChannel(StreamChannel delegate, long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit, long writeTimeout, java.util.concurrent.TimeUnit writeTimeoutUnit)
delegate
- the channel to forward I/O operations toreadTimeout
- the read timeoutreadTimeoutUnit
- the read timeout unitwriteTimeout
- the write timeoutwriteTimeoutUnit
- the write timeout unitpublic void setReadTimeout(long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit)
readTimeout
- the read timeoutreadTimeoutUnit
- the read timeout unitpublic void setWriteTimeout(long writeTimeout, java.util.concurrent.TimeUnit writeTimeoutUnit)
writeTimeout
- the write timeoutwriteTimeoutUnit
- the write timeout unitpublic long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
read
in interface java.nio.channels.ScatteringByteChannel
dsts
- the destination buffersoffset
- the offset into the destination buffer arraylength
- the number of buffers to read intojava.io.IOException
- if an I/O error occurspublic long read(java.nio.ByteBuffer[] dsts) throws java.io.IOException
read
in interface java.nio.channels.ScatteringByteChannel
dsts
- the destination buffersjava.io.IOException
- if an I/O error occurspublic int read(java.nio.ByteBuffer dst) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
dst
- the destination bufferjava.io.IOException
- if an I/O error occurspublic long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
write
in interface java.nio.channels.GatheringByteChannel
srcs
- the source buffersoffset
- the offset into the destination buffer arraylength
- the number of buffers to write fromjava.io.IOException
- if an I/O error occurspublic long write(java.nio.ByteBuffer[] srcs) throws java.io.IOException
write
in interface java.nio.channels.GatheringByteChannel
srcs
- the source buffersjava.io.IOException
- if an I/O error occurspublic int write(java.nio.ByteBuffer src) throws java.io.IOException
write
in interface java.nio.channels.WritableByteChannel
src
- the source bufferjava.io.IOException
- if an I/O error occurspublic boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
Copyright © 2016 JBoss, a division of Red Hat, Inc.