Class IoUtils


  • public final class IoUtils
    extends java.lang.Object
    • Method Detail

      • toUrl

        public static java.net.URL toUrl​(java.net.URI uri)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • isUriLike

        public static boolean isUriLike​(java.lang.String str)
        Checks whether the given string is "URI-like", i.e. matches a pattern like foo:bar.
      • toUri

        public static java.net.URI toUri​(java.lang.String str)
                                  throws java.net.URISyntaxException
        Converts the given string to a URI. This method MUST be used for constructing module and resource URIs. Unlike new URI(str), it correctly escapes paths of relative URIs.
        Throws:
        java.net.URISyntaxException
      • createUri

        public static java.net.URI createUri​(java.lang.String str)
        Like toUri(String), except without checked exceptions.
      • stripFragment

        public static java.net.URI stripFragment​(java.net.URI uri)
      • readString

        public static java.lang.String readString​(java.net.URL url)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readString

        public static java.lang.String readString​(java.io.InputStream inputStream)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readBytes

        public static byte[] readBytes​(java.net.URL url)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readString

        public static java.lang.String readString​(java.io.Reader reader)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readClassPathResourceAsString

        public static java.lang.String readClassPathResourceAsString​(java.lang.Class<?> clazz,
                                                                     java.lang.String path)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • zipDirectory

        public static void zipDirectory​(java.nio.file.Path sourceDir,
                                        java.nio.file.Path targetFile)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getCurrentWorkingDir

        public static java.nio.file.Path getCurrentWorkingDir()
      • getPklHomeDir

        public static java.nio.file.Path getPklHomeDir()
      • getDefaultModuleCacheDir

        public static java.nio.file.Path getDefaultModuleCacheDir()
      • getLineSeparator

        public static java.lang.String getLineSeparator()
      • getName

        public static java.lang.String getName​(java.lang.String path)
      • getName

        public static java.lang.String getName​(java.nio.file.Path path)
      • getNameWithoutExtension

        public static java.lang.String getNameWithoutExtension​(java.lang.String path)
      • takeLastSegment

        public static java.lang.String takeLastSegment​(java.lang.String name,
                                                       char separator)
      • dropLastSegment

        public static java.lang.String dropLastSegment​(java.lang.String name,
                                                       char separator)
      • toPath

        public static @Nullable java.nio.file.Path toPath​(java.net.URI uri)
      • inferModuleName

        public static java.lang.String inferModuleName​(ModuleKey moduleKey)
      • ensurePathEndsWithSlash

        public static java.net.URI ensurePathEndsWithSlash​(java.net.URI uri)
      • resolve

        public static java.net.URI resolve​(ReaderBase reader,
                                           java.net.URI baseUri,
                                           java.lang.String importUri)
      • resolve

        public static java.net.URI resolve​(ReaderBase reader,
                                           java.net.URI baseUri,
                                           java.net.URI importUri)
      • resolve

        public static java.net.URI resolve​(java.net.URI baseUri,
                                           java.net.URI newUri)
      • resolve

        public static java.net.URI resolve​(java.net.URI uri,
                                           java.lang.String str)
      • relativize

        public static java.net.URI relativize​(java.net.URI uri,
                                              java.net.URI base)
      • isWhitespace

        public static boolean isWhitespace​(java.lang.String str)
      • capitalize

        public static java.lang.String capitalize​(java.lang.String str)
        Capitalizes the first Unicode character of the given string (rather than the first character of each word).
      • getMaxLineLength

        public static int getMaxLineLength​(java.lang.String str)
      • createServiceLoader

        public static <T> java.util.ServiceLoader<T> createServiceLoader​(java.lang.Class<T> serviceClass)
      • isTestMode

        public static boolean isTestMode()
      • setTestMode

        public static void setTestMode()
      • parseTripleDotPath

        public static @Nullable java.lang.String parseTripleDotPath​(java.net.URI importUri)
                                                             throws java.net.URISyntaxException
        Throws:
        java.net.URISyntaxException
      • toUnicodeEscape

        public static java.lang.String toUnicodeEscape​(int ch)
      • toHexEscape

        public static java.lang.String toHexEscape​(int ch)
      • isHexDigit

        public static boolean isHexDigit​(char ch)
      • isHexDigitOrUnderscore

        public static boolean isHexDigitOrUnderscore​(char ch)
      • isDecimalDigit

        public static boolean isDecimalDigit​(char ch)
      • isDecimalDigitOrUnderscore

        public static boolean isDecimalDigitOrUnderscore​(char ch)
      • isNonZeroDecimalDigit

        public static boolean isNonZeroDecimalDigit​(char ch)
      • isOctalDigit

        public static boolean isOctalDigit​(char ch)
      • isOctalDigitOrUnderscore

        public static boolean isOctalDigitOrUnderscore​(char ch)
      • isBinaryDigitOrUnderscore

        public static boolean isBinaryDigitOrUnderscore​(char ch)
      • fixTripleSlashUri

        public static java.net.URI fixTripleSlashUri​(java.net.URI baseUri,
                                                     java.net.URI newUri)
        Fix an issue where triple-slash URI's turn into single-slash URI's when using URI.resolve(URI)