Package jodd.io
Class NetUtil
- java.lang.Object
-
- jodd.io.NetUtil
-
public class NetUtil extends java.lang.ObjectNetwork utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_MASKstatic intINT_VALUE_127_0_0_1static java.lang.StringLOCAL_HOSTstatic java.lang.StringLOCAL_IP
-
Constructor Summary
Constructors Constructor Description NetUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]downloadBytes(java.lang.String url)Downloads resource as byte array.static voiddownloadFile(java.lang.String url, java.io.File file)Downloads resource to a file, potentially very efficiently.static java.lang.StringdownloadString(java.lang.String url)Downloads resource as String.static java.lang.StringdownloadString(java.lang.String url, java.nio.charset.Charset encoding)Downloads resource as String.static intgetIpAsInt(java.lang.String ipAddress)Returns IP address as integer.static intgetMaskAsInt(java.lang.String mask)static longgetRemoteFileSize(java.lang.String url)Get remote file size.static booleanisSocketAccessAllowed(int localIp, int socketIp, int mask)static java.lang.StringresolveHostName(byte[] ip)Resolves host name from IP address bytes.static java.lang.StringresolveIpAddress(java.lang.String hostname)Resolves IP address from a hostname.static booleanvalidateIPv4(java.lang.String input)Checks given string against IP address v4 format.
-
-
-
Field Detail
-
LOCAL_HOST
public static final java.lang.String LOCAL_HOST
- See Also:
- Constant Field Values
-
LOCAL_IP
public static final java.lang.String LOCAL_IP
- See Also:
- Constant Field Values
-
DEFAULT_MASK
public static final java.lang.String DEFAULT_MASK
- See Also:
- Constant Field Values
-
INT_VALUE_127_0_0_1
public static final int INT_VALUE_127_0_0_1
- See Also:
- Constant Field Values
-
-
Method Detail
-
resolveIpAddress
public static java.lang.String resolveIpAddress(java.lang.String hostname)
Resolves IP address from a hostname.
-
getIpAsInt
public static int getIpAsInt(java.lang.String ipAddress)
Returns IP address as integer.
-
getMaskAsInt
public static int getMaskAsInt(java.lang.String mask)
-
isSocketAccessAllowed
public static boolean isSocketAccessAllowed(int localIp, int socketIp, int mask)
-
validateIPv4
public static boolean validateIPv4(java.lang.String input)
Checks given string against IP address v4 format.- Parameters:
input- an ip address - may be null- Returns:
- true if param has a valid ip v4 format false otherwise
- See Also:
- ip address v4
-
resolveHostName
public static java.lang.String resolveHostName(byte[] ip)
Resolves host name from IP address bytes.
-
downloadBytes
public static byte[] downloadBytes(java.lang.String url) throws java.io.IOExceptionDownloads resource as byte array.- Throws:
java.io.IOException
-
downloadString
public static java.lang.String downloadString(java.lang.String url, java.nio.charset.Charset encoding) throws java.io.IOExceptionDownloads resource as String.- Throws:
java.io.IOException
-
downloadString
public static java.lang.String downloadString(java.lang.String url) throws java.io.IOExceptionDownloads resource as String.- Throws:
java.io.IOException
-
downloadFile
public static void downloadFile(java.lang.String url, java.io.File file) throws java.io.IOExceptionDownloads resource to a file, potentially very efficiently.- Throws:
java.io.IOException
-
getRemoteFileSize
public static long getRemoteFileSize(java.lang.String url) throws java.io.IOExceptionGet remote file size. Returns -1 if the content length is unknown- Parameters:
url- remote file url- Returns:
- file size
- Throws:
java.io.IOException- JDK-IOException
-
-