public class NetworkOutputStream
extends java.io.OutputStream
Socket
s or DatagramSocket
s.Constructor and Description |
---|
NetworkOutputStream(java.net.DatagramSocket socketIn)
Constructs a new NetworkOutputStream with the specified
DatagramSocket . |
NetworkOutputStream(java.net.DatagramSocket socketIn,
int size)
Constructs a new NetworkOutputStream with the specified
DatagramSocket and datagram buffer size. |
NetworkOutputStream(java.net.DatagramSocket socketIn,
int size,
java.net.InetAddress address,
int port)
Constructs a new NetworkOutputStream with the specified
DatagramSocket , datagram buffer size, InetAddress target and port target. |
NetworkOutputStream(java.net.Socket socketIn)
Constructs a new NetworkOutputStream with the specified
Socket . |
Modifier and Type | Method and Description |
---|---|
boolean |
canDatagramBufferBeSet()
Gets if the
setDatagramBufferSize(int) can be used. |
void |
close()
Closes this output stream and releases any system resources
associated with this stream.
|
void |
flush()
Flushes this output stream and forces any buffered output bytes
to be written out.
|
java.net.InetAddress |
getAddress()
Gets the current
InetAddress of the stream. |
java.net.DatagramSocket |
getDatagramSocket()
Gets the datagram socket in use or null.
|
java.net.InetAddress |
getLocalAddress()
Gets the local
InetAddress of the stream. |
java.lang.Integer |
getLocalPort()
Gets the local port of the stream.
|
java.lang.Integer |
getPort()
Gets the current port of the stream.
|
java.net.Socket |
getSocket()
Gets the socket in use or null.
|
void |
setDatagramBufferSize(int size)
Sets the buffer size for sending datagrams.
|
void |
setDatagramSocket(java.net.DatagramSocket socketIn)
Sets the datagram socket in use.
|
void |
setDatagramTarget(java.net.InetAddress address,
int port)
Sets the datagram target
InetAddress and port. |
void |
setSocket(java.net.Socket socketIn)
Sets the socket in use.
|
void |
write(int b)
Writes the specified byte to this output stream.
|
public NetworkOutputStream(java.net.Socket socketIn)
Socket
.socketIn
- The socket to use.java.lang.NullPointerException
- socketIn is null.public NetworkOutputStream(java.net.DatagramSocket socketIn)
DatagramSocket
.socketIn
- The datagram socket to use.java.lang.NullPointerException
- socketIn is null.public NetworkOutputStream(java.net.DatagramSocket socketIn, int size)
DatagramSocket
and datagram buffer size.socketIn
- The datagram socket to use.size
- The size of the buffer.java.lang.NullPointerException
- socketIn is null.java.lang.IllegalArgumentException
- size is less than 1 or greater than 65535.public NetworkOutputStream(java.net.DatagramSocket socketIn, int size, java.net.InetAddress address, int port)
DatagramSocket
, datagram buffer size, InetAddress
target and port target.socketIn
- The datagram socket to use.size
- The size of the buffer.address
- The target address to set to.port
- The target port to set to.java.lang.NullPointerException
- socketIn or address is null.java.lang.IllegalArgumentException
- size is less than 1 or greater than 65535 or port is less than 0 or greater than 65535.public boolean canDatagramBufferBeSet()
setDatagramBufferSize(int)
can be used.public void setDatagramBufferSize(int size) throws java.io.IOException
size
- The size to set to.java.lang.IllegalArgumentException
- size is less than 1 or greater than 65535.java.io.IOException
- a datagram socket is not in use, buffer index is not null or the stream is closed.public void setDatagramTarget(java.net.InetAddress address, int port) throws java.io.IOException
InetAddress
and port.address
- The address to set to.port
- The port to set to.java.lang.NullPointerException
- address is null.java.lang.IllegalArgumentException
- port is less than 0 or greater than 65535.java.io.IOException
- a datagram socket is not in use or the stream is closed.public void write(int b) throws java.io.IOException
write
is that one byte is written
to the output stream. The byte to be written is the eight
low-order bits of the argument b
. The 24
high-order bits of b
are ignored.write
in class java.io.OutputStream
b
- the byte
.java.io.IOException
- if an I/O error occurs. In particular,
an IOException
will be thrown if the
output stream has been closed.public java.net.InetAddress getAddress()
InetAddress
of the stream.
Can be null.public java.lang.Integer getPort()
public java.net.InetAddress getLocalAddress()
InetAddress
of the stream.
Can be null.public java.lang.Integer getLocalPort()
public java.net.Socket getSocket()
public void setSocket(java.net.Socket socketIn) throws java.io.IOException
socketIn
- The socket to now use.java.lang.NullPointerException
- socketIn is null.java.io.IOException
- stream closed or not using a socket.public java.net.DatagramSocket getDatagramSocket()
public void setDatagramSocket(java.net.DatagramSocket socketIn) throws java.io.IOException
socketIn
- The datagram socket to now use.java.lang.NullPointerException
- socketIn is null.java.io.IOException
- stream closed or not using a datagram socket.public void flush() throws java.io.IOException
flush
is
that calling it is an indication that, if any bytes previously
written have been buffered by the implementation of the output
stream, such bytes should immediately be written to their
intended destination.flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
- if an I/O error occurs.public void close() throws java.io.IOException
close
is that it closes the output stream. A closed stream cannot perform
output operations and cannot be reopened. The underlying socket is closed.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
- if an I/O error occurs.