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
`static com.google.common.base.Supplier<Path>` `DEPLOYED_BASE_PATH`
`static String` `FILE_SCHEME`
`static String` `LEMMINX_WORKDIR_KEY`

### Method Summary

All Methods Static Methods Concrete Methods
`static String` `convertToWindowsPath​(String pathString)` Ensures there is no slash before a drive letter, and forces use of '\'
`static String` `encodePath​(String path)` Replace spaces with "%20".
`static String` `getCachePathSetting()`
`static Path` `getDeployedPath​(Path path)` Returns the deployed path from the given `path`.
`static String` `getFileName​(Path path)` Returns the file name of the given path.
`static String` `getFilePathSlash​(String text)` Returns the slash ("/" or "\") that is used by the given string.
`static int` `getOffsetAfterScheme​(String uri)`
`static Path` `getPath​(String uri)` Returns the IO Path from the given uri.
`static boolean` `isIncludedInDeployedPath​(Path resourceCachePath)`
`static boolean` `isValidPath​(Path path)` Returns true if the file at the given path exists.
`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.
`static boolean` `pathEndsWithFile​(String pathString)`
`static String` `readString​(Path path)` Very simple implementation of reading all content from a file into a string using the UTF-8 charset.
`static String` `removeFileScheme​(String fileURI)` Remove the file:// scheme from the given file URI.
`static void` `resetDeployPath()` Public for test purposes
`static void` `saveToFile​(InputStream in, Path outFile)` Save the given input stream `in` in the give out file `outFile`
`static void` `saveToFile​(String content, Path outFile)` Save the given String `content` in the give out file `outFile`
`static void` `setCachePathSetting​(String cachePathSetting)`
`static File` `toFile​(String fileUri)` Convert the given file Uri to a File.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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 given `path`.

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 stream `in` in the give out file `outFile`

Parameters:
  `in` - the input stream
  `outFile` - the output file
Throws:
  `IOException`

#### saveToFile

    public static void saveToFile​(String content,
                                  Path outFile)
                           throws IOException

Save the given String `content` in the give out file `outFile`

Parameters:
  `content` - the string content
  `outFile` - 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.

#### getFileName

    public static String getFileName​(Path path)

Returns the file name of the given path.

Parameters:
  `path` - the path.
Returns:
  the file name of the given path.