Class FileUtil

java.lang.Object
org.eclipse.epsilon.common.util.FileUtil

public class FileUtil extends Object
  • Method Details

    • getCurrentDirectory

      public static Path getCurrentDirectory()
    • setFileContents

      public static void setFileContents(String str, File file) throws Exception
      Throws:
      Exception
    • replaceExtension

      public static String replaceExtension(String filename, String newExtension)
    • removeExtension

      public static String removeExtension(String filename)
    • getFileName

      public static String getFileName(String path)
    • getFileName

      public static String getFileName(String path, boolean includeExtension)
    • getExtension

      public static String getExtension(String filename)
      Copied from @linkplain{https://stackoverflow.com/a/3571239/5870336}
      Parameters:
      filename -
      Returns:
      Since:
      1.6
    • getFileContents

      public static String getFileContents(File file) throws Exception
      Throws:
      Exception
    • getFileLineContents

      public static Collection<String> getFileLineContents(File file) throws Exception
      Throws:
      Exception
    • getAbsolutePath

      public static String getAbsolutePath(String basePath, String relativePath)
    • isInJarFile

      public static boolean isInJarFile()
      Returns:
      Since:
      1.6
    • isInJarFile

      public static boolean isInJarFile(Class<?> clazz)
      Parameters:
      clazz -
      Returns:
      Since:
      1.6
    • getStandalonePath

      public static Path getStandalonePath(String dir, Class<?> relativeTo) throws IOException
      Throws:
      IOException
    • getDirectoryStandalone

      public static File getDirectoryStandalone(String dir, Class<?> relativeTo) throws IOException
      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

      public static File getFileStandalone(String name, Class<?> relativeTo) throws IOException
      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

      public static File getFileURL(String name, Class<?> relativeTo)
      The getFile method of old, before we tried to fix it to work in JAR files.
      Parameters:
      name -
      relativeTo -
      Returns:
      Since:
      1.6
    • getDirectoryOf

      public static File getDirectoryOf(Class<?> clazz) throws IOException
      Throws:
      IOException
    • getPath

      public static String getPath(String name, Class<?> relativeTo) throws IOException
      Throws:
      IOException
    • checkFileExists

      public static void checkFileExists(File file) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • copyToTemp

      public static File copyToTemp(File srcFile) throws IOException
      Throws:
      IOException
    • copy

      public static void copy(File srcFile, File dstFile) throws IOException
      Throws:
      IOException
    • listFilesAsSet

      public static Set<String> listFilesAsSet(File fileExpected)
    • sameContents

      public static boolean sameContents(File fileExpected, File fileActual, Set<String> ignoreFilenames) 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(InputStream isExpected, InputStream isActual) throws IOException
      Throws:
      IOException
    • stringToPath

      public static Path stringToPath(String dir)
      Parameters:
      dir -
      Returns:
      Since:
      1.6
    • deleteDirectory

      public static void deleteDirectory(String dir) throws IOException
      Parameters:
      path -
      Throws:
      IOException
      Since:
      1.6
    • deleteDirectory

      public static void deleteDirectory(Path path) throws IOException
      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

      public static Map<Path,byte[]> readDirectory(String dir) throws IOException
      Parameters:
      dir -
      Returns:
      Throws:
      IOException
      Since:
      1.6
    • readDirectory

      public static Map<Path,byte[]> readDirectory(Path dir) throws IOException
      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

      public static File createTempFile(String name)
      Parameters:
      name -
      Returns:
      Since:
      1.6
    • createTempFile

      public static File createTempFile(String name, String extension)
      Parameters:
      name -
      extension -
      Returns:
      Since:
      1.6
    • createTempDir

      public static File createTempDir(String name)
      Parameters:
      name -
      Returns:
      Since:
      1.6
    • createTempDir

      public static File createTempDir(String name, boolean reuse)
      Parameters:
      name -
      reuse -
      Returns:
      Since:
      1.6