Class FileUtil

java.lang.Object
org.ampere.base.util.FileUtil
All Implemented Interfaces:
PACTEdef

public class FileUtil extends Object implements PACTEdef
Utilities for files
Author:
hmorel
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • buildAndCreateDirectory

      public static File buildAndCreateDirectory(File parent, String dirName)
      Build or Create a subdirectory
      Parameters:
      parent - parent directory
      dirName - new directory name
      Returns:
      te built or created directory
    • getOrCreate

      public static File getOrCreate(Path dirp)
    • addIndex

      public static File addIndex(File original, int index)
      add an index to a file befor the extension
      Parameters:
      original - input file
      index - given index
      Returns:
      the new file
    • getIndex

      public static Integer getIndex(File file)
    • increment

      public static File increment(File original)
    • buildAbsolute

      public static Path buildAbsolute(Path workingDirectory, String relativePath)
      Build an absolute path with a relative unix path, as ../somepath Notice that tha parameter workingDirectory is not necessarily the current working directory of the user.
      Parameters:
      workingDirectory - considered working directory, i.e. a brother file of the return one.
      relativePath - input relative path that must start by ../
      Returns:
      the built absolute path.
    • buildAbsolute

      public static Path buildAbsolute(Path dir, String child, String... following)
      Build an absolute path to a brother file having path, as ../somepath Notice that tha parameter workingDirectory is not necessarily the current working directory of the user.
      Parameters:
      dir - considered working directory, i.e. a brother file of the return one.
      Returns:
      the built absolute path.
    • buildOrCreateDirectory

      public static File buildOrCreateDirectory(File wdir, String relativePath2dir)
      Build or create the associated directory
      Parameters:
      wdir - considered working directory
      relativePath2dir - relative path to the targeted directory
      Returns:
      the built or created directory
    • buildAbsolute

      public static Path buildAbsolute(Path parent, List<String> list)
    • validateExtension

      public static File validateExtension(File file, String extension)
      Validate a file to have a given extension.
      Parameters:
      file - input file to be validated
      extension - without a dot.
      Returns:
      a file with the input extension.
    • changeExtension

      public static File changeExtension(File file, String extension)
      Validate a file to have a given extension.
      Parameters:
      file - input file to be validated
      extension - without a dot.
      Returns:
      a file with the input extension.
    • rename

      public static void rename(File oldFile, String newFileName)
      rename in a same directory
      Parameters:
      oldFile - old file
      newFileName - new file name
    • getFile

      public static File getFile(File[] files, String filename)
      Get the file of the array matching the input name
      Parameters:
      files - array of files
      filename - targeted filename
      Returns:
      the found file or null.
    • buildWriter

      public static PrintWriter buildWriter(File file)
    • withoutExtension

      public static String withoutExtension(String path)
      Remove a posible extension to a path
      Parameters:
      path - string to be analysed
      Returns:
      the input string without its extension, i.e. a final dot + a string.
    • getExtension

      public static String getExtension(String path)
      Remove a posible extension to a path
      Parameters:
      path - string to be analysed
      Returns:
      the input string without its extension, i.e. a final dot + a string.
    • withoutExtension

      public static File withoutExtension(File file)
      Parameters:
      file - input file
      Returns:
      the input File without its extension, i.e. a final dot + a string.
    • hasExtension

      public static boolean hasExtension(File file, String extension)
      Test if a file has a given extension or not
      Parameters:
      file - file to be tested
      extension - targeted extension without the dot
      Returns:
      true if the input file as the specified extension
    • completeName

      public static File completeName(File file, String complement)
      Build a new File by completing the name without changing its extention.
      Parameters:
      file - input file
      complement - filename complement
      Returns:
      the built File with the new complement
    • printFullFileName

      public static void printFullFileName(PrintWriter out, File file)
    • buildFrom

      public static File buildFrom(File dir, String spath)
      build a file from an absolute or a relative path with true system path validation.
      Parameters:
      dir - reference directory for relative path
      spath - relative or absolute path
      Returns:
      the built file
    • buildFileReader

      public static FileReader buildFileReader(File file)
    • buildFileInputStream

      public static FileInputStream buildFileInputStream(File file)