java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel@LimitedPrivate({"HDFS","MapReduce"})
@Unstable
public class SocketOutputStream
extends java.io.OutputStream
implements java.nio.channels.WritableByteChannel
Socket.getInputStream() and write() on
Socket.getOutputStream() on the associated socket will throw
llegalBlockingModeException.
Please use SocketInputStream for reading.| Constructor | Description |
|---|---|
SocketOutputStream(java.net.Socket socket,
long timeout) |
Same as SocketOutputStream(socket.getChannel(), timeout):
Create a new ouput stream with the given timeout. |
SocketOutputStream(java.nio.channels.WritableByteChannel channel,
long timeout) |
Create a new ouput stream with the given timeout.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
java.nio.channels.WritableByteChannel |
getChannel() |
|
boolean |
isOpen() |
|
void |
setTimeout(int timeoutMs) |
|
void |
transferToFully(java.nio.channels.FileChannel fileCh,
long position,
int count) |
Call
transferToFully(FileChannel, long, int, LongWritable, LongWritable)
with null waitForWritableTime and transferToTime. |
void |
transferToFully(java.nio.channels.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) |
|
void |
write(int b) |
|
int |
write(java.nio.ByteBuffer src) |
public SocketOutputStream(java.nio.channels.WritableByteChannel channel,
long timeout)
throws java.io.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.java.io.IOException - raised on errors performing I/O.public SocketOutputStream(java.net.Socket socket,
long timeout)
throws java.io.IOException
socket - should have a channel associated with it.timeout - timeout timeout in milliseconds. must not be negative.java.io.IOException - raised on errors performing I/O.SocketOutputStream(WritableByteChannel, long)public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in interface java.io.Closeableclose in class java.io.OutputStreamjava.io.IOExceptionpublic java.nio.channels.WritableByteChannel getChannel()
FileChannel.transferTo(long, long, WritableByteChannel)public boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic int write(java.nio.ByteBuffer src)
throws java.io.IOException
write in interface java.nio.channels.WritableByteChanneljava.io.IOExceptionpublic void waitForWritable()
throws java.io.IOException
java.net.SocketTimeoutException - if select on the channel times out.java.io.IOException - if any other I/O error occurs.public void transferToFully(java.nio.channels.FileChannel fileCh,
long position,
int count,
LongWritable waitForWritableTime,
LongWritable transferToTime)
throws java.io.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 writabletransferToTime - nanoseconds spent transferring datajava.io.EOFException - If end of input file is reached before requested number of
bytes are transfered.java.net.SocketTimeoutException - If this channel blocks transfer longer than timeout for
this stream.java.io.IOException - Includes any exception thrown by
FileChannel.transferTo(long, long, WritableByteChannel).public void transferToFully(java.nio.channels.FileChannel fileCh,
long position,
int count)
throws java.io.IOException
transferToFully(FileChannel, long, int, LongWritable, LongWritable)
with null waitForWritableTime and transferToTime.fileCh - input fileCh.position - input position.count - input count.java.io.IOException - raised on errors performing I/O.public void setTimeout(int timeoutMs)
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.