Package org.eclipse.epsilon.common.util
Class FileUtil
java.lang.Object
org.eclipse.epsilon.common.util.FileUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckFileExists(File file) static voidstatic FilecopyToTemp(File srcFile) static FilecreateTempDir(String name) static FilecreateTempDir(String name, boolean reuse) static FilecreateTempFile(String name) static FilecreateTempFile(String name, String extension) static voiddeleteDirectory(String dir) static voiddeleteDirectory(Path path) WARNIING: Use with caution! Deletes all contents and sub-directories of the specified path.static StringgetAbsolutePath(String basePath, String relativePath) static Pathstatic FilegetDirectoryOf(Class<?> clazz) static FilegetDirectoryStandalone(String dir, Class<?> relativeTo) Convenience method for copying all files from the workspace / JAR path (relative to the class) to temp folder.static StringgetExtension(String filename) Copied from @linkplain{https://stackoverflow.com/a/3571239/5870336}static StringgetFileContents(File file) static Collection<String>getFileLineContents(File file) static StringgetFileName(String path) static StringgetFileName(String path, boolean includeExtension) static FilegetFileStandalone(String name, Class<?> relativeTo) Gets a file stored as a resource in a jar.static FilegetFileURL(String name, Class<?> relativeTo) The getFile method of old, before we tried to fix it to work in JAR files.static Stringstatic PathgetStandalonePath(String dir, Class<?> relativeTo) static booleanstatic booleanisInJarFile(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 StringremoveExtension(String filename) static StringreplaceExtension(String filename, String newExtension) static booleansameContents(File fileExpected, File fileActual, Set<String> ignoreFilenames) static booleansameContents(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 booleansameContents(InputStream isExpected, InputStream isActual) static voidsetFileContents(String str, File file) static PathstringToPath(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:
IOExceptionURISyntaxException- 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
-