|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.net.NetUtil
public final class NetUtil
Provides static utility methods that deal with networking.
This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).
Nested Class Summary | |
---|---|
static class |
NetUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Constructor Summary | |
---|---|
private |
NetUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class. |
Method Summary | |
---|---|
static URL |
getFtpUrl(String filenameRemote,
String host,
String username,
String password)
Returns a new URL instance that specifies filenameRemote on the remote host. |
static String |
getSocketState(Socket socket)
Returns a String which lists all of socket's publicly accessible state. |
static boolean |
isValidPort(int port)
Determines whether or not port is a valid TCP or UDP port number. |
static void |
writeFileToUrl(File file,
URL url,
PrintWriter logger)
Writes file to url. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private NetUtil()
Method Detail |
---|
public static boolean isValidPort(int port)
NumberUtil.unsigned2ByteMaxValue
).
See TCP and UDP port.
public static String getSocketState(Socket socket) throws IllegalArgumentException, SocketException
IllegalArgumentException
- if any socket == null
SocketException
- if there is an error in the underlying protocol, such as a TCP errorpublic static URL getFtpUrl(String filenameRemote, String host, String username, String password) throws IllegalArgumentException, RuntimeException
"ftp://" + username + ":" + password + "@" + host + "/" + filenameRemote + ";type=i"
Thus, the host value should not end with a '/' char, nor should filenameRemote begin with a '/' char.
Warning: the ftp protocol is completely insecure, with the username and password along with all data being sent in the clear.
IllegalArgumentException
- if any arg is null
RuntimeException
- if any arg causes the ftp URL to be malformedpublic static void writeFileToUrl(File file, URL url, PrintWriter logger) throws IllegalArgumentException, IOException
logger
- is passed to StreamUtil.transfer(in, out, logger)
IllegalArgumentException
- if file is not valid
; url == null
IOException
- if an I/O problem occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |