Package net.sf.basedb.util
Class SocketUtil
- java.lang.Object
-
- net.sf.basedb.util.SocketUtil
-
public class SocketUtil extends Object
This class contains some useful methods when working with sockets. Mainly for easy reading and writing to/from the sockets, and also for closing sockets without throwing exceptions.- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2011-10-12 14:45:07 +0200 (on, 12 okt 2011) $
-
-
Field Summary
Fields Modifier and Type Field Description private static InetAddress
LOCAL_HOST
-
Constructor Summary
Constructors Constructor Description SocketUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
close(InputStream in)
Close anInputStream
without throwing any exceptions.static void
close(Reader in)
Close aReader
without throwing any exceptions.static void
close(Writer out)
Close aWriter
without throwing any exceptions.static void
close(ServerSocket socket)
Close a server socket without throwing any exceptions.static void
close(Socket socket)
Close a socket without throwing any exceptions.static void
close(ServerSocketChannel socket)
Close a server socket channel 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.
-
-
-
Field Detail
-
LOCAL_HOST
private static InetAddress LOCAL_HOST
-
-
Method Detail
-
send
public static void send(Socket socket, String output, boolean shutdownOutput) throws IOException
Send output to a socket.- Parameters:
socket
- The socket to send tooutput
- The output to sendshutdownOutput
- TRUE to close the output stream, FALSE to leave it open- Throws:
IOException
- If there is an error
-
read
public static String read(Socket socket, boolean shutdownInput) throws IOException
Read input from a socket.- Parameters:
socket
- The socket to read fromshutdownInput
- If the input stream should be closed or not- Returns:
- The data that was read
- Throws:
IOException
- If there is an error
-
close
public static void close(Socket socket)
Close a socket without throwing any exceptions.- Parameters:
socket
- The socket to close
-
close
public static void close(ServerSocketChannel socket)
Close a server socket channel without throwing any exceptions.- Parameters:
socket
- The socket to close
-
close
public static void close(ServerSocket socket)
Close a server socket without throwing any exceptions.- Parameters:
socket
- The socket to close
-
close
public static void close(Writer out)
Close aWriter
without throwing any exceptions.- Parameters:
out
- The writer to close
-
close
public static void close(Reader in)
Close aReader
without throwing any exceptions.- Parameters:
in
- The reader to close
-
close
public static void close(InputStream in)
Close anInputStream
without throwing any exceptions.- Parameters:
in
- The stream to close
-
isLocalHost
public static boolean isLocalHost(InetAddress address)
Check if the specfied address is the local host or not.- Parameters:
address
- The address to check- Returns:
- TRUE if the address represents the local host, FALSE otherwise
-
getLocalHost
public static InetAddress getLocalHost()
Get the local address of the local host.
-
getPublicLocalHost
public static InetAddress getPublicLocalHost()
Get the external address of the local host.
-
-