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