@InterfaceAudience.LimitedPrivate(value={"HDFS","MapReduce"}) @InterfaceStability.Unstable public class SocketOutputStream extends OutputStream implements WritableByteChannel
Socket.getInputStream() and write() on
Socket.getOutputStream() on the associated socket will throw
llegalBlockingModeException.
Please use SocketInputStream for reading.| Constructor and Description |
|---|
SocketOutputStream(Socket socket,
long timeout)
Same as SocketOutputStream(socket.getChannel(), timeout):
Create a new ouput stream with the given timeout. |
SocketOutputStream(WritableByteChannel channel,
long timeout)
Create a new ouput stream with the given timeout.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
WritableByteChannel |
getChannel()
Returns underlying channel used by this stream.
|
boolean |
isOpen() |
void |
setTimeout(int timeoutMs) |
void |
transferToFully(FileChannel fileCh,
long position,
int count)
Call
#transferToFully(FileChannel, long, int, MutableRate, MutableRate)
with null waitForWritableTime and transferToTime |
void |
transferToFully(FileChannel fileCh,
long position,
int count,
LongWritable waitForWritableTime,
LongWritable transferToTime)
Transfers data from FileChannel using
FileChannel.transferTo(long, long, WritableByteChannel). |
void |
waitForWritable()
waits for the underlying channel to be ready for writing.
|
void |
write(byte[] b,
int off,
int len) |
int |
write(ByteBuffer src) |
void |
write(int b) |
flush, writepublic SocketOutputStream(WritableByteChannel channel, long timeout) throws IOException
channel - Channel for writing, should also be a SelectableChannel.
The channel will be configured to be non-blocking.timeout - timeout in milliseconds. must not be negative.IOExceptionpublic SocketOutputStream(Socket socket, long timeout) throws IOException
socket - should have a channel associated with it.timeout - timeout timeout in milliseconds. must not be negative.IOExceptionSocketOutputStream(WritableByteChannel, long)public void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in class OutputStreamIOExceptionpublic WritableByteChannel getChannel()
FileChannel.transferTo(long, long, WritableByteChannel)public int write(ByteBuffer src) throws IOException
write in interface WritableByteChannelIOExceptionpublic void waitForWritable()
throws IOException
SocketTimeoutException - if select on the channel times out.IOException - if any other I/O error occurs.public void transferToFully(FileChannel fileCh, long position, int count, LongWritable waitForWritableTime, LongWritable transferToTime) throws IOException
FileChannel.transferTo(long, long, WritableByteChannel).
Updates waitForWritableTime and transferToTime
with the time spent blocked on the network and the time spent transferring
data from disk to network respectively.
Similar to readFully(), this waits till requested amount of
data is transfered.fileCh - FileChannel to transfer data from.position - position within the channel where the transfer beginscount - number of bytes to transfer.waitForWritableTime - nanoseconds spent waiting for the socket
to become writabletransferTime - nanoseconds spent transferring dataEOFException - If end of input file is reached before requested number of
bytes are transfered.SocketTimeoutException - If this channel blocks transfer longer than timeout for
this stream.IOException - Includes any exception thrown by
FileChannel.transferTo(long, long, WritableByteChannel).public void transferToFully(FileChannel fileCh, long position, int count) throws IOException
#transferToFully(FileChannel, long, int, MutableRate, MutableRate)
with null waitForWritableTime and transferToTimeIOExceptionpublic void setTimeout(int timeoutMs)
Copyright © 2013 Apache Software Foundation. All rights reserved.