Package jodd.io

Class NetUtil


  • public class NetUtil
    extends java.lang.Object
    Network utilities.
    • 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 void downloadFile​(java.lang.String url, java.io.File file)
      Downloads resource to a file, potentially very efficiently.
      static java.lang.String downloadString​(java.lang.String url)
      Downloads resource as String.
      static java.lang.String downloadString​(java.lang.String url, java.nio.charset.Charset encoding)
      Downloads resource as String.
      static int getIpAsInt​(java.lang.String ipAddress)
      Returns IP address as integer.
      static int getMaskAsInt​(java.lang.String mask)  
      static long getRemoteFileSize​(java.lang.String url)
      Get remote file size.
      static boolean isSocketAccessAllowed​(int localIp, int socketIp, int mask)  
      static java.lang.String resolveHostName​(byte[] ip)
      Resolves host name from IP address bytes.
      static java.lang.String resolveIpAddress​(java.lang.String hostname)
      Resolves IP address from a hostname.
      static boolean validateIPv4​(java.lang.String input)
      Checks given string against IP address v4 format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NetUtil

        public NetUtil()
    • 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.IOException
        Downloads 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.IOException
        Downloads resource as String.
        Throws:
        java.io.IOException
      • downloadString

        public static java.lang.String downloadString​(java.lang.String url)
                                               throws java.io.IOException
        Downloads resource as String.
        Throws:
        java.io.IOException
      • downloadFile

        public static void downloadFile​(java.lang.String url,
                                        java.io.File file)
                                 throws java.io.IOException
        Downloads resource to a file, potentially very efficiently.
        Throws:
        java.io.IOException
      • getRemoteFileSize

        public static long getRemoteFileSize​(java.lang.String url)
                                      throws java.io.IOException
        Get 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