Package org.pkl.core.util
Class IoUtils
- java.lang.Object
-
- org.pkl.core.util.IoUtils
-
public final class IoUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringcapitalize(java.lang.String str)Capitalizes the first Unicode character of the given string (rather than the first character of each word).static <T> java.util.ServiceLoader<T>createServiceLoader(java.lang.Class<T> serviceClass)static java.net.URIcreateUri(java.lang.String str)LiketoUri(String), except without checked exceptions.static java.lang.StringdropLastSegment(java.lang.String name, char separator)static java.net.URIensurePathEndsWithSlash(java.net.URI uri)static java.net.URIfixTripleSlashUri(java.net.URI baseUri, java.net.URI newUri)Fix an issue where triple-slash URI's turn into single-slash URI's when usingURI.resolve(URI)static java.nio.file.PathgetCurrentWorkingDir()static java.nio.file.PathgetDefaultModuleCacheDir()static java.lang.StringgetLineSeparator()static intgetMaxLineLength(java.lang.String str)static java.lang.StringgetName(java.lang.String path)static java.lang.StringgetName(java.nio.file.Path path)static java.lang.StringgetNameWithoutExtension(java.lang.String path)static java.nio.file.PathgetPklHomeDir()static java.lang.StringinferModuleName(ModuleKey moduleKey)static booleanisBinaryDigitOrUnderscore(char ch)static booleanisDecimalDigit(char ch)static booleanisDecimalDigitOrUnderscore(char ch)static booleanisHexDigit(char ch)static booleanisHexDigitOrUnderscore(char ch)static booleanisNonZeroDecimalDigit(char ch)static booleanisOctalDigit(char ch)static booleanisOctalDigitOrUnderscore(char ch)static booleanisTestMode()static booleanisUriLike(java.lang.String str)Checks whether the given string is "URI-like", i.e.static booleanisWhitespace(java.lang.String str)static @Nullable java.lang.StringparseTripleDotPath(java.net.URI importUri)static byte[]readBytes(java.net.URL url)static java.lang.StringreadClassPathResourceAsString(java.lang.Class<?> clazz, java.lang.String path)static java.lang.StringreadString(java.io.InputStream inputStream)static java.lang.StringreadString(java.io.Reader reader)static java.lang.StringreadString(java.net.URL url)static java.net.URIrelativize(java.net.URI uri, java.net.URI base)static java.net.URIresolve(java.net.URI uri, java.lang.String str)static java.net.URIresolve(java.net.URI baseUri, java.net.URI newUri)static java.net.URIresolve(ReaderBase reader, java.net.URI baseUri, java.lang.String importUri)static java.net.URIresolve(ReaderBase reader, java.net.URI baseUri, java.net.URI importUri)static java.net.URIresolve(SecurityManager securityManager, ModuleKey moduleKey, java.net.URI importUri)ResolvesimportUriagainst the module key.static voidsetTestMode()static java.net.URIstripFragment(java.net.URI uri)static java.lang.StringtakeLastSegment(java.lang.String name, char separator)static java.lang.StringtoHexEscape(int ch)static @Nullable java.nio.file.PathtoPath(java.net.URI uri)static java.lang.StringtoUnicodeEscape(int ch)static java.net.URItoUri(java.lang.String str)Converts the given string to aURI.static java.net.URLtoUrl(java.net.URI uri)static voidzipDirectory(java.nio.file.Path sourceDir, java.nio.file.Path targetFile)
-
-
-
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 likefoo:bar.
-
toUri
public static java.net.URI toUri(java.lang.String str) throws java.net.URISyntaxExceptionConverts the given string to aURI. This method MUST be used for constructing module and resource URIs. Unlikenew URI(str), it correctly escapes paths of relative URIs.- Throws:
java.net.URISyntaxException
-
createUri
public static java.net.URI createUri(java.lang.String str)
LiketoUri(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(SecurityManager securityManager, ModuleKey moduleKey, java.net.URI importUri) throws java.net.URISyntaxException, java.io.IOException, SecurityManagerException
ResolvesimportUriagainst the module key.When
importUricontains a triple-dot, it is resolved if the module key returns true for bothModuleKey.isLocal()andReaderBase.hasHierarchicalUris(). Otherwise, an error is thrown.- Throws:
java.net.URISyntaxExceptionjava.io.IOExceptionSecurityManagerException
-
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 usingURI.resolve(URI)
-
-