Package org.eclipse.lemminx.utils
Class FilesUtils
java.lang.Object
org.eclipse.lemminx.utils.FilesUtils
Files utilities.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertToWindowsPath(String pathString) Ensures there is no slash before a drive letter, and forces use of '\'static StringencodePath(String path) Replace spaces with "%20".static Stringstatic PathgetDeployedPath(Path path) Returns the deployed path from the givenpath.static StringgetFilePathSlash(String text) Returns the slash ("/" or "\") that is used by the given string.static intstatic PathReturns the IO Path from the given uri.static booleanisIncludedInDeployedPath(Path resourceCachePath) static booleanisValidPath(Path path) Returns true if the file at the given path exists.static StringnormalizePath(String pathString) Given a file path as a string, will normalize it and return the normalized string if valid, or null if not.static booleanpathEndsWithFile(String pathString) static StringreadString(Path path) Very simple implementation of reading all content from a file into a string using the UTF-8 charset.static StringremoveFileScheme(String fileURI) Remove the file:// scheme from the given file URI.static voidPublic for test purposesstatic voidsaveToFile(InputStream in, Path outFile) Save the given input streaminin the give out fileoutFilestatic voidsaveToFile(String content, Path outFile) Save the given Stringcontentin the give out fileoutFilestatic voidsetCachePathSetting(String cachePathSetting) static FileConvert the given file Uri to a File.
-
Field Details
-
FILE_SCHEME
- See Also:
-
LEMMINX_WORKDIR_KEY
- See Also:
-
DEPLOYED_BASE_PATH
-
-
Method Details
-
getCachePathSetting
-
setCachePathSetting
-
resetDeployPath
public static void resetDeployPath()Public for test purposes -
normalizePath
Given a file path as a string, will normalize it and return the normalized string if valid, or null if not. The '~' home symbol will be converted into the actual home path. Slashes will be corrected depending on the OS. -
getDeployedPath
Returns the deployed path from the givenpath.- Parameters:
path- the path- Returns:
- the deployed path from the given
path. - Throws:
IOException
-
saveToFile
Save the given input streaminin the give out fileoutFile- Parameters:
in- the input streamoutFile- the output file- Throws:
IOException
-
saveToFile
Save the given Stringcontentin the give out fileoutFile- Parameters:
content- the string contentoutFile- the output file- Throws:
IOException
-
getOffsetAfterScheme
-
getFilePathSlash
Returns the slash ("/" or "\") that is used by the given string. If no slash is given "/" is returned by default.- Parameters:
text-- Returns:
-
convertToWindowsPath
Ensures there is no slash before a drive letter, and forces use of '\'- Parameters:
pathString-- Returns:
-
pathEndsWithFile
-
isIncludedInDeployedPath
-
removeFileScheme
Remove the file:// scheme from the given file URI.- Parameters:
fileURI- the file URI.- Returns:
- the file URI without file scheme.
-
toFile
Convert the given file Uri to a File.- Parameters:
fileUri- the file Uri.- Returns:
- the given file Uri to a File.
-
getPath
Returns the IO Path from the given uri. This URI can use several syntaxes like:- file:///C:/folder (Windows OS), file://home (Linux OS)
- a%20b/folder (folder with spaces)
- Parameters:
uri- the URI- Returns:
- the IO Path from the given uri.
-
encodePath
Replace spaces with "%20".- Parameters:
path- the path.- Returns:
- the path with replaced spaces.
-
readString
Very simple implementation of reading all content from a file into a string using the UTF-8 charset. Uses the System's line separator. Not suited for reading large files.- Parameters:
path- the path to a readable file.- Returns:
- the contents of the file.
- Throws:
IOException- if an error occurred while reading the file.
-
isValidPath
Returns true if the file at the given path exists.- Parameters:
path- the path.- Returns:
- true if the file at the given path exists.
-