public class SocketUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.net.InetAddress |
LOCAL_HOST |
Constructor and Description |
---|
SocketUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
close(java.io.InputStream in)
Close an
InputStream without throwing any exceptions. |
static void |
close(java.io.Reader in)
Close a
Reader without throwing any exceptions. |
static void |
close(java.net.ServerSocket socket)
Close a server socket without throwing any exceptions.
|
static void |
close(java.nio.channels.ServerSocketChannel socket)
Close a server socket channel without throwing any exceptions.
|
static void |
close(java.net.Socket socket)
Close a socket without throwing any exceptions.
|
static void |
close(java.io.Writer out)
Close a
Writer without throwing any exceptions. |
static java.net.InetAddress |
getLocalHost()
Get the local address of the local host.
|
static java.net.InetAddress |
getPublicLocalHost()
Get the external address of the local host.
|
static boolean |
isLocalHost(java.net.InetAddress address)
Check if the specfied address is the local host or not.
|
static java.lang.String |
read(java.net.Socket socket,
boolean shutdownInput)
Read input from a socket.
|
static void |
send(java.net.Socket socket,
java.lang.String output,
boolean shutdownOutput)
Send output to a socket.
|
public static void send(java.net.Socket socket, java.lang.String output, boolean shutdownOutput) throws java.io.IOException
socket
- The socket to send tooutput
- The output to sendshutdownOutput
- TRUE to close the output stream, FALSE to leave it openjava.io.IOException
- If there is an errorpublic static java.lang.String read(java.net.Socket socket, boolean shutdownInput) throws java.io.IOException
socket
- The socket to read fromshutdownInput
- If the input stream should be closed or notjava.io.IOException
- If there is an errorpublic static void close(java.net.Socket socket)
socket
- The socket to closepublic static void close(java.nio.channels.ServerSocketChannel socket)
socket
- The socket to closepublic static void close(java.net.ServerSocket socket)
socket
- The socket to closepublic static void close(java.io.Writer out)
Writer
without throwing any exceptions.out
- The writer to closepublic static void close(java.io.Reader in)
Reader
without throwing any exceptions.in
- The reader to closepublic static void close(java.io.InputStream in)
InputStream
without throwing any exceptions.in
- The stream to closepublic static boolean isLocalHost(java.net.InetAddress address)
address
- The address to checkpublic static java.net.InetAddress getLocalHost()
public static java.net.InetAddress getPublicLocalHost()