Package org.eclipse.epsilon.common.util
Class FileUtil
java.lang.Object
org.eclipse.epsilon.common.util.FileUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkFileExists
(File file) static void
static File
copyToTemp
(File srcFile) static File
createTempDir
(String name) static File
createTempDir
(String name, boolean reuse) static File
createTempFile
(String name) static File
createTempFile
(String name, String extension) static void
deleteDirectory
(String dir) static void
deleteDirectory
(Path path) WARNIING: Use with caution! Deletes all contents and sub-directories of the specified path.static String
getAbsolutePath
(String basePath, String relativePath) static Path
static File
getDirectoryOf
(Class<?> clazz) static File
getDirectoryStandalone
(String dir, Class<?> relativeTo) Convenience method for copying all files from the workspace / JAR path (relative to the class) to temp folder.static String
getExtension
(String filename) Copied from @linkplain{https://stackoverflow.com/a/3571239/5870336}static String
getFileContents
(File file) static Collection<String>
getFileLineContents
(File file) static String
getFileName
(String path) static String
getFileName
(String path, boolean includeExtension) static File
getFileStandalone
(String name, Class<?> relativeTo) Gets a file stored as a resource in a jar.static File
getFileURL
(String name, Class<?> relativeTo) The getFile method of old, before we tried to fix it to work in JAR files.static String
static Path
getStandalonePath
(String dir, Class<?> relativeTo) static boolean
static boolean
isInJarFile
(Class<?> clazz) listFilesAsSet
(File fileExpected) readDirectory
(String dir) readDirectory
(Path dir) Reads entire directory recursively, mapping the contents of each file as a string to its path.static String
removeExtension
(String filename) static String
replaceExtension
(String filename, String newExtension) static boolean
sameContents
(File fileExpected, File fileActual, Set<String> ignoreFilenames) static boolean
sameContents
(File fileExpected, File fileActual, Set<String> ignoreFilenames, boolean ignoreLineEndings) We implement our own comparison algorithm here, so we don't need Eclipse Compare to compute differences, but rather only to show them in the UI.static boolean
sameContents
(InputStream isExpected, InputStream isActual) static void
setFileContents
(String str, File file) static Path
stringToPath
(String dir)
-
Method Details
-
getCurrentDirectory
-
setFileContents
- Throws:
Exception
-
replaceExtension
-
removeExtension
-
getFileName
-
getFileName
-
getExtension
Copied from @linkplain{https://stackoverflow.com/a/3571239/5870336}- Parameters:
filename
-- Returns:
- Since:
- 1.6
-
getFileContents
- Throws:
Exception
-
getFileLineContents
- Throws:
Exception
-
getAbsolutePath
-
isInJarFile
public static boolean isInJarFile()- Returns:
- Since:
- 1.6
-
isInJarFile
- Parameters:
clazz
-- Returns:
- Since:
- 1.6
-
getStandalonePath
- Throws:
IOException
-
getDirectoryStandalone
Convenience method for copying all files from the workspace / JAR path (relative to the class) to temp folder. Used for tests.- Parameters:
dir
-relativeTo
-- Returns:
- Throws:
IOException
URISyntaxException
- Since:
- 1.6
- See Also:
-
getFileStandalone
Gets a file stored as a resource in a jar. Since not all users of the file can read from inside jars, we get the file as a stream and create a temp file with its contents.- Parameters:
name
-relativeTo
-- Returns:
- Throws:
IOException
- Since:
- 1.6
-
getFileURL
The getFile method of old, before we tried to fix it to work in JAR files.- Parameters:
name
-relativeTo
-- Returns:
- Since:
- 1.6
-
getDirectoryOf
- Throws:
IOException
-
getPath
- Throws:
IOException
-
checkFileExists
- Throws:
FileNotFoundException
-
copyToTemp
- Throws:
IOException
-
copy
- Throws:
IOException
-
listFilesAsSet
-
sameContents
public static boolean sameContents(File fileExpected, File fileActual, Set<String> ignoreFilenames, boolean ignoreLineEndings) throws IOException We implement our own comparison algorithm here, so we don't need Eclipse Compare to compute differences, but rather only to show them in the UI.- Throws:
IOException
-
sameContents
public static boolean sameContents(File fileExpected, File fileActual, Set<String> ignoreFilenames) throws IOException - Throws:
IOException
-
sameContents
- Throws:
IOException
-
stringToPath
- Parameters:
dir
-- Returns:
- Since:
- 1.6
-
deleteDirectory
- Parameters:
path
-- Throws:
IOException
- Since:
- 1.6
-
deleteDirectory
WARNIING: Use with caution! Deletes all contents and sub-directories of the specified path.- Parameters:
dir
- The absolute path to the directory.- Throws:
IOException
- Since:
- 1.6
-
readDirectory
- Parameters:
dir
-- Returns:
- Throws:
IOException
- Since:
- 1.6
-
readDirectory
Reads entire directory recursively, mapping the contents of each file as a string to its path.- Parameters:
dir
- The root directory.- Returns:
- The contents of each file in the directory and its subdirectories.
- Throws:
IOException
- Since:
- 1.6
-
createTempFile
- Parameters:
name
-- Returns:
- Since:
- 1.6
-
createTempFile
- Parameters:
name
-extension
-- Returns:
- Since:
- 1.6
-
createTempDir
- Parameters:
name
-- Returns:
- Since:
- 1.6
-
createTempDir
- Parameters:
name
-reuse
-- Returns:
- Since:
- 1.6
-