Class IoUtils

java.lang.Object
org.pkl.core.util.IoUtils

public final class IoUtils extends Object
  • Method Details

    • toUrl

      public static URL toUrl(URI uri) throws IOException
      Throws:
      IOException
    • isUriLike

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

      public static boolean isWindowsAbsolutePath(String str)
    • toUri

      public static URI toUri(String str) throws 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:
      URISyntaxException
    • pathOf

      public static Path pathOf(URI uri)
      Converts a URI to a Path, normalizing any non-ASCII characters.
    • createUri

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

      public static URI stripFragment(URI uri)
    • readString

      public static String readString(URL url) throws IOException
      Throws:
      IOException
    • readString

      public static String readString(InputStream inputStream) throws IOException
      Throws:
      IOException
    • readBytes

      public static byte[] readBytes(URI uri) throws IOException
      Throws:
      IOException
    • readString

      public static String readString(Reader reader) throws IOException
      Throws:
      IOException
    • readClassPathResourceAsString

      public static String readClassPathResourceAsString(Class<?> clazz, String path) throws IOException
      Throws:
      IOException
    • zipDirectory

      public static void zipDirectory(Path sourceDir, Path targetFile) throws IOException
      Throws:
      IOException
    • getCurrentWorkingDir

      public static Path getCurrentWorkingDir()
    • getPklHomeDir

      public static Path getPklHomeDir()
    • getDefaultModuleCacheDir

      public static Path getDefaultModuleCacheDir()
    • getLineSeparator

      public static String getLineSeparator()
    • isWindows

      public static Boolean isWindows()
    • getName

      public static String getName(String path)
    • getName

      public static String getName(Path path)
    • getNameWithoutExtension

      public static String getNameWithoutExtension(String path)
    • takeLastSegment

      public static String takeLastSegment(String name, char separator)
    • dropLastSegment

      public static String dropLastSegment(String name, char separator)
    • toPath

      @Nullable public static @Nullable Path toPath(URI uri)
    • inferModuleName

      public static String inferModuleName(ModuleKey moduleKey)
    • ensurePathEndsWithSlash

      public static URI ensurePathEndsWithSlash(URI uri)
    • resolve

      public static URI resolve(ReaderBase reader, URI baseUri, String importUri)
    • resolve

      public static URI resolve(ReaderBase reader, URI baseUri, URI importUri)
    • parseDependencyNotation

      public static Pair<String,String> parseDependencyNotation(String importPath)
    • resolve

      public static URI resolve(SecurityManager securityManager, ModuleKey moduleKey, URI importUri) throws URISyntaxException, IOException, SecurityManagerException, ExternalReaderProcessException
      Resolves importUri against the module key.

      When importUri contains a triple-dot, it is resolved if the module key returns true for both ModuleKey.isLocal() and ReaderBase.hasHierarchicalUris(). Otherwise, an error is thrown.

      When importUri starts with a @, it is resolved if the module key supports dependency notation ()

      Throws:
      URISyntaxException
      IOException
      SecurityManagerException
      ExternalReaderProcessException
    • resolve

      public static URI resolve(URI baseUri, URI newUri)
    • resolve

      public static URI resolve(URI uri, String str)
    • relativize

      public static URI relativize(URI uri, URI base)
    • relativize

      public static Path relativize(Path path, Path base)
    • isWhitespace

      public static boolean isWhitespace(String str)
    • capitalize

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

      public static int getMaxLineLength(String str)
    • createServiceLoader

      public static <T> ServiceLoader<T> createServiceLoader(Class<T> serviceClass)
    • isTestMode

      public static boolean isTestMode()
    • setTestMode

      public static void setTestMode()
    • setSystemProxy

      public static void setSystemProxy(URI proxyAddress)
    • parseTripleDotPath

      @Nullable public static @Nullable String parseTripleDotPath(URI importUri) throws URISyntaxException
      Throws:
      URISyntaxException
    • toUnicodeEscape

      public static String toUnicodeEscape(int ch)
    • toHexEscape

      public static 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 URI fixTripleSlashUri(URI baseUri, URI newUri)
      Fix an issue where triple-slash URI's turn into single-slash URI's when using URI.resolve(URI)
    • isReservedFilenameChar

      public static boolean isReservedFilenameChar(char character)
    • isReservedWindowsFilenameChar

      public static boolean isReservedWindowsFilenameChar(char character)
      Tells if this character cannot be used for filenames on Windows.
    • encodePath

      public static String encodePath(String path)
      Windows reserves characters <>:"\|?* in filenames.

      For any such characters, enclose their decimal character code with parentheses. Verbatim ( is encoded as ((.

    • toNormalizedPathString

      public static String toNormalizedPathString(Path path)
      Returns a path string that uses unix-like path separators.
    • validateFileUri

      public static void validateFileUri(URI uri) throws URISyntaxException
      Throws:
      URISyntaxException
    • validateRewriteRule

      public static void validateRewriteRule(URI rewrite)