public class NetUtils extends Object
| Constructor and Description |
|---|
NetUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addStaticResolution(String host,
String resolvedName)
Adds a static resolution for host.
|
static void |
connect(Socket socket,
SocketAddress endpoint,
int timeout) |
static InetSocketAddress |
createSocketAddr(String target)
Util method to build socket addr from either:
|
static InetSocketAddress |
createSocketAddr(String target,
int defaultPort)
Util method to build socket addr from either:
|
static List<String[]> |
getAllStaticResolutions()
This is used to get all the resolutions that were added using
addStaticResolution(String, String). |
static InetSocketAddress |
getConnectAddress(Server server)
Returns InetSocketAddress that a client can use to
connect to the server.
|
static SocketFactory |
getDefaultSocketFactory() |
static InputStream |
getInputStream(Socket socket)
Same as getInputStream(socket, socket.getSoTimeout()).
From documentation for getInputStream(Socket, long):Returns InputStream for the socket. |
static InputStream |
getInputStream(Socket socket,
long timeout)
Returns InputStream for the socket.
|
static OutputStream |
getOutputStream(Socket socket)
Same as getOutputStream(socket, 0).
|
static OutputStream |
getOutputStream(Socket socket,
long timeout)
Returns OutputStream for the socket.
|
static SocketFactory |
getSocketFactory() |
static String |
getStaticResolution(String host)
Retrieves the resolved name for the passed host.
|
static String |
normalizeHostName(String name)
Given a string representation of a host, return its ip address
in textual presentation.
|
static List<String> |
normalizeHostNames(Collection<String> names)
Given a collection of string representation of hosts, return a list of
corresponding IP addresses in the textual representation.
|
public static SocketFactory getSocketFactory()
public static SocketFactory getDefaultSocketFactory()
public static InetSocketAddress createSocketAddr(String target)
public static InetSocketAddress createSocketAddr(String target, int defaultPort)
public static void addStaticResolution(String host, String resolvedName)
getStaticResolution(String) can be used to query for
the actual hostname.host - resolvedName - public static String getStaticResolution(String host)
addStaticResolution(String, String)host - public static List<String[]> getAllStaticResolutions()
addStaticResolution(String, String). The return
value is a List each element of which contains an array of String
of the form String[0]=hostname, String[1]=resolved-hostnamepublic static InetSocketAddress getConnectAddress(Server server)
server - public static InputStream getInputStream(Socket socket) throws IOException
getInputStream(Socket, long):SocketInputStream with the given timeout. If the socket does not
have a channel, Socket.getInputStream() is returned. In the later
case, the timeout argument is ignored and the timeout set with Socket.setSoTimeout(int) applies for
reads.NetUtils(),
must use this interface instead of Socket.getInputStream().socket - IOExceptiongetInputStream(Socket, long)public static InputStream getInputStream(Socket socket, long timeout) throws IOException
SocketInputStream with the given timeout. If the socket does not
have a channel, Socket.getInputStream() is returned. In the later
case, the timeout argument is ignored and the timeout set with Socket.setSoTimeout(int) applies for
reads.NetUtils(),
must use this interface instead of Socket.getInputStream().socket - timeout - timeout in milliseconds. This may not always apply. zero
for waiting as long as necessary.IOExceptionSocket.getChannel()public static OutputStream getOutputStream(Socket socket) throws IOException
getOutputStream(Socket, long) : SocketOutputStream with the given timeout. If the socket does not
have a channel, Socket.getOutputStream() is returned. In the later
case, the timeout argument is ignored and the write will wait until
data is available.NetUtils(),
must use this interface instead of Socket.getOutputStream().socket - IOExceptiongetOutputStream(Socket, long)public static OutputStream getOutputStream(Socket socket, long timeout) throws IOException
SocketOutputStream with the given timeout. If the socket does not
have a channel, Socket.getOutputStream() is returned. In the later
case, the timeout argument is ignored and the write will wait until
data is available.NetUtils(),
must use this interface instead of Socket.getOutputStream().socket - timeout - timeout in milliseconds. This may not always apply. zero
for waiting as long as necessary.IOExceptionSocket.getChannel()public static void connect(Socket socket, SocketAddress endpoint, int timeout) throws IOException
IOExceptionpublic static String normalizeHostName(String name)
name - a string representation of a host:
either a textual representation its IP address or its host namepublic static List<String> normalizeHostNames(Collection<String> names)
names - a collection of string representations of hostsnormalizeHostName(String)Copyright © 2014 The Apache Software Foundation. All rights reserved.