2.17.2: 2011-06-17

net.sf.basedb.util
Class SocketUtil

java.lang.Object
  extended by 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: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $

Field Summary
private static InetAddress LOCAL_HOST
           
 
Constructor Summary
SocketUtil()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCAL_HOST

private static InetAddress LOCAL_HOST
Constructor Detail

SocketUtil

public SocketUtil()
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 to
output - The output to send
shutdownOutput - 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 from
shutdownInput - 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 a Writer without throwing any exceptions.

Parameters:
out - The writer to close

close

public static void close(Reader in)
Close a Reader without throwing any exceptions.

Parameters:
in - The reader to close

close

public static void close(InputStream in)
Close an InputStream 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.


2.17.2: 2011-06-17