Package org.eclipse.lemminx.utils
Class FilesUtils
- java.lang.Object
-
- org.eclipse.lemminx.utils.FilesUtils
-
public class FilesUtils extends Object
Files utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.base.Supplier<Path>DEPLOYED_BASE_PATHstatic StringFILE_SCHEMEstatic StringLEMMINX_WORKDIR_KEY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 StringgetCachePathSetting()static PathgetDeployedPath(Path path)Returns the deployed path from the givenpath.static StringgetFileName(Path path)Returns the file name of the given path.static StringgetFilePathSlash(String text)Returns the slash ("/" or "\") that is used by the given string.static intgetOffsetAfterScheme(String uri)static PathgetPath(String uri)Returns 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 voidresetDeployPath()Public 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 FiletoFile(String fileUri)Convert the given file Uri to a File.
-
-
-
Field Detail
-
FILE_SCHEME
public static final String FILE_SCHEME
- See Also:
- Constant Field Values
-
LEMMINX_WORKDIR_KEY
public static final String LEMMINX_WORKDIR_KEY
- See Also:
- Constant Field Values
-
DEPLOYED_BASE_PATH
public static com.google.common.base.Supplier<Path> DEPLOYED_BASE_PATH
-
-
Method Detail
-
getCachePathSetting
public static String getCachePathSetting()
-
setCachePathSetting
public static void setCachePathSetting(String cachePathSetting)
-
resetDeployPath
public static void resetDeployPath()
Public for test purposes
-
normalizePath
public static String normalizePath(String pathString)
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
public static Path getDeployedPath(Path path) throws IOException
Returns the deployed path from the givenpath.- Parameters:
path- the path- Returns:
- the deployed path from the given
path. - Throws:
IOException
-
saveToFile
public static void saveToFile(InputStream in, Path outFile) throws IOException
Save the given input streaminin the give out fileoutFile- Parameters:
in- the input streamoutFile- the output file- Throws:
IOException
-
saveToFile
public static void saveToFile(String content, Path outFile) throws IOException
Save the given Stringcontentin the give out fileoutFile- Parameters:
content- the string contentoutFile- the output file- Throws:
IOException
-
getOffsetAfterScheme
public static int getOffsetAfterScheme(String uri)
-
getFilePathSlash
public static String getFilePathSlash(String text)
Returns the slash ("/" or "\") that is used by the given string. If no slash is given "/" is returned by default.- Parameters:
text-- Returns:
-
convertToWindowsPath
public static String convertToWindowsPath(String pathString)
Ensures there is no slash before a drive letter, and forces use of '\'- Parameters:
pathString-- Returns:
-
pathEndsWithFile
public static boolean pathEndsWithFile(String pathString)
-
isIncludedInDeployedPath
public static boolean isIncludedInDeployedPath(Path resourceCachePath)
-
removeFileScheme
public static String removeFileScheme(String fileURI)
Remove the file:// scheme from the given file URI.- Parameters:
fileURI- the file URI.- Returns:
- the file URI without file scheme.
-
toFile
public static File toFile(String fileUri)
Convert the given file Uri to a File.- Parameters:
fileUri- the file Uri.- Returns:
- the given file Uri to a File.
-
getPath
public static Path getPath(String uri)
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
public static String encodePath(String path)
Replace spaces with "%20".- Parameters:
path- the path.- Returns:
- the path with replaced spaces.
-
readString
public static String readString(Path path) throws IOException
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
public static boolean isValidPath(Path path)
Returns true if the file at the given path exists.- Parameters:
path- the path.- Returns:
- true if the file at the given path exists.
-
-