Package net.sf.basedb.util
Class SocketUtil
java.lang.Object
net.sf.basedb.util.SocketUtil
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
close
(InputStream in) Close anInputStream
without throwing any exceptions.static void
Close aReader
without throwing any exceptions.static void
Close aWriter
without throwing any exceptions.static void
close
(ServerSocket socket) Close a server socket without throwing any exceptions.static void
Close a socket without throwing any exceptions.static void
close
(ServerSocketChannel socket) Close a server socket channel without throwing any exceptions.static InetAddress
Get the local address of the local host.static InetAddress
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 input from a socket.static void
Send output to a socket.
-
Field Details
-
LOCAL_HOST
-
-
Constructor Details
-
SocketUtil
public SocketUtil()
-
-
Method Details
-
send
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
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
Close a socket without throwing any exceptions.- Parameters:
socket
- The socket to close
-
close
Close a server socket channel without throwing any exceptions.- Parameters:
socket
- The socket to close
-
close
Close a server socket without throwing any exceptions.- Parameters:
socket
- The socket to close
-
close
Close aWriter
without throwing any exceptions.- Parameters:
out
- The writer to close
-
close
Close aReader
without throwing any exceptions.- Parameters:
in
- The reader to close
-
close
Close anInputStream
without throwing any exceptions.- Parameters:
in
- The stream to close
-
isLocalHost
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
Get the local address of the local host. -
getPublicLocalHost
Get the external address of the local host.
-