Class JarUtils


  • public final class JarUtils
    extends java.lang.Object
    Jarfile utilities.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.regex.Pattern DASH_VERSION
      The Constant DASH_VERSION.
      private static java.util.regex.Pattern LEADING_DOTS
      The Constant LEADING_DOTS.
      private static java.util.regex.Pattern NON_ALPHANUM
      The Constant NON_ALPHANUM.
      private static java.util.regex.Pattern REPEATING_DOTS
      The Constant REPEATING_DOTS.
      private static java.util.regex.Pattern TRAILING_DOTS
      The Constant TRAILING_DOTS.
      private static int[] UNIX_NON_PATH_SEPARATOR_COLON_POSITIONS
      The position of the colon characters in the corresponding UNIX_NON_PATH_SEPARATORS array entry.
      private static java.lang.String[] UNIX_NON_PATH_SEPARATORS
      On everything but Windows, where the path separator is ':', need to treat the colon in these substrings as non-separators, when at the beginning of the string or following a ':'.
      static java.util.regex.Pattern URL_SCHEME_PATTERN
      Check if a path has a URL scheme at the beginning.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private JarUtils()
      Constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void appendPathElt​(java.lang.Object pathElt, java.lang.StringBuilder buf)
      Append a path element to a buffer.
      static java.lang.String classfilePathToClassName​(java.lang.String classfilePath)
      Convert a classfile path to the corresponding class name.
      static java.lang.String classNameToClassfilePath​(java.lang.String className)
      Convert a class name to the corresponding classfile path.
      static java.lang.String derivedAutomaticModuleName​(java.lang.String jarPath)
      Derive automatic module name from jar name, using this algorithm.
      static java.lang.String leafName​(java.lang.String path)
      Returns the leafname of a path, after first stripping off everything after the first '!', if present.
      static java.lang.String pathElementsToPathStr​(java.lang.Iterable<?> pathElts)
      Get a set of path elements as a string, from an array of objects (e.g.
      static java.lang.String pathElementsToPathStr​(java.lang.Object... pathElts)
      Get a set of path elements as a string, from an array of objects (e.g.
      static java.lang.String[] smartPathSplit​(java.lang.String pathStr, char separatorChar, ScanSpec scanSpec)
      Split a path on the given separator char.
      static java.lang.String[] smartPathSplit​(java.lang.String pathStr, ScanSpec scanSpec)
      Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g.
      • Methods inherited from class java.lang.Object

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

      • URL_SCHEME_PATTERN

        public static final java.util.regex.Pattern URL_SCHEME_PATTERN
        Check if a path has a URL scheme at the beginning. Require at least 2 chars in a URL scheme, so that Windows drive designations don't get treated as URL schemes.
      • DASH_VERSION

        private static final java.util.regex.Pattern DASH_VERSION
        The Constant DASH_VERSION.
      • NON_ALPHANUM

        private static final java.util.regex.Pattern NON_ALPHANUM
        The Constant NON_ALPHANUM.
      • REPEATING_DOTS

        private static final java.util.regex.Pattern REPEATING_DOTS
        The Constant REPEATING_DOTS.
      • LEADING_DOTS

        private static final java.util.regex.Pattern LEADING_DOTS
        The Constant LEADING_DOTS.
      • TRAILING_DOTS

        private static final java.util.regex.Pattern TRAILING_DOTS
        The Constant TRAILING_DOTS.
      • UNIX_NON_PATH_SEPARATORS

        private static final java.lang.String[] UNIX_NON_PATH_SEPARATORS
        On everything but Windows, where the path separator is ':', need to treat the colon in these substrings as non-separators, when at the beginning of the string or following a ':'.
      • UNIX_NON_PATH_SEPARATOR_COLON_POSITIONS

        private static final int[] UNIX_NON_PATH_SEPARATOR_COLON_POSITIONS
        The position of the colon characters in the corresponding UNIX_NON_PATH_SEPARATORS array entry.
    • Constructor Detail

      • JarUtils

        private JarUtils()
        Constructor.
    • Method Detail

      • smartPathSplit

        public static java.lang.String[] smartPathSplit​(java.lang.String pathStr,
                                                        ScanSpec scanSpec)
        Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g. "http://domain/jar1.jar:http://domain/jar2.jar".
        Parameters:
        pathStr - The path to split.
        scanSpec - the scan spec
        Returns:
        The path element substrings.
      • smartPathSplit

        public static java.lang.String[] smartPathSplit​(java.lang.String pathStr,
                                                        char separatorChar,
                                                        ScanSpec scanSpec)
        Split a path on the given separator char. If the separator char is ':', also allow for the use of URLs with protocol specifiers, e.g. "http://domain/jar1.jar:http://domain/jar2.jar".
        Parameters:
        pathStr - The path to split.
        separatorChar - The separator char to use.
        scanSpec - the scan spec
        Returns:
        The path element substrings.
      • appendPathElt

        private static void appendPathElt​(java.lang.Object pathElt,
                                          java.lang.StringBuilder buf)
        Append a path element to a buffer.
        Parameters:
        pathElt - the path element
        buf - the buf
      • pathElementsToPathStr

        public static java.lang.String pathElementsToPathStr​(java.lang.Object... pathElts)
        Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.
        Parameters:
        pathElts - The path elements.
        Returns:
        The delimited path formed out of the path elements.
      • pathElementsToPathStr

        public static java.lang.String pathElementsToPathStr​(java.lang.Iterable<?> pathElts)
        Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.
        Parameters:
        pathElts - The path elements.
        Returns:
        The delimited path formed out of the path elements, after calling each of their toString() methods.
      • leafName

        public static java.lang.String leafName​(java.lang.String path)
        Returns the leafname of a path, after first stripping off everything after the first '!', if present.
        Parameters:
        path - A file path.
        Returns:
        The leafname of the path.
      • classfilePathToClassName

        public static java.lang.String classfilePathToClassName​(java.lang.String classfilePath)
        Convert a classfile path to the corresponding class name.
        Parameters:
        classfilePath - the classfile path
        Returns:
        the class name
      • classNameToClassfilePath

        public static java.lang.String classNameToClassfilePath​(java.lang.String className)
        Convert a class name to the corresponding classfile path.
        Parameters:
        className - the class name
        Returns:
        the classfile path
      • derivedAutomaticModuleName

        public static java.lang.String derivedAutomaticModuleName​(java.lang.String jarPath)
        Derive automatic module name from jar name, using this algorithm.
        Parameters:
        jarPath - The jar path.
        Returns:
        The automatic module name.