public class ChannelOutputStream extends OutputStream
ByteBuffer
before writing it to a channel.Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
buffer
Holds data until it is written.
|
protected WritableByteChannel |
channel
The channel where the data will be written.
|
Constructor and Description |
---|
ChannelOutputStream(WritableByteChannel out)
Creates the stream from the channel where the data will be written.
|
ChannelOutputStream(WritableByteChannel out,
int size)
Creates the stream from the channel where the data will be written and a buffer size.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
|
void |
flush()
Forces any buffered output bytes to be written to
channel . |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array starting at offset
off to this channel output stream. |
void |
write(int b)
Writes the specified byte to this channel output stream.
|
write
protected ByteBuffer buffer
protected WritableByteChannel channel
public ChannelOutputStream(WritableByteChannel out)
out
- The channel where the data will be written.public ChannelOutputStream(WritableByteChannel out, int size)
out
- The channel where the data will be written.size
- The buffer size.public void write(int b) throws IOException
write
in class OutputStream
b
- The byte to be written.IOException
- Possible while flush()
ing.public void write(byte[] b, int off, int len) throws IOException
len
bytes from the specified byte array starting at offset
off
to this channel output stream.write
in class OutputStream
b
- The data.off
- The start offset in the data.len
- The number of bytes to write.IOException
- Possible while flush()
ing.public void flush() throws IOException
channel
.flush
in interface Flushable
flush
in class OutputStream
IOException
- Possible while writing to channel
.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- Possible while closing channel
.Copyright © 2016. All rights reserved.