Class KFileUtil

java.lang.Object
com.kheops.util.KFileUtil

public class KFileUtil extends Object
KFileUtil contains usefull methods for files manipulation.
  • Constructor Details

    • KFileUtil

      public KFileUtil()
  • Method Details

    • listFiles

      public static File[] listFiles(String dir, String[] filters, boolean recursive)
      Lists all files matching the specified filters from the specified directory. The filter '*' returns all files. ex.: listFiles(new File("c:/temp"), new String[]{"*"});
      Parameters:
      dir - the directory to list files from
      filters - filters to match the files with
      Returns:
      all files matching the specified filter from the specified directory
    • listFiles

      public static File[] listFiles(File dir, String[] filters, boolean recursive)
      Lists all files matching the specified filters from the specified directory. The filter '*' returns all files. ex.: listFiles(new File("c:/temp"), new String[]{"*"});
      Parameters:
      dir - the directory to list files from
      filters - filters to match the files with
      Returns:
      all files matching the specified filter from the specified directory
    • listFiles

      public static File[] listFiles(String dir, String[] filters)
      Lists all files matching the specified filters from the specified directory. The filter '*' returns all files. ex.: listFiles(new File("c:/temp"), new String[]{"*"});
      Parameters:
      dir - the directory to list files from
      filters - filters to match the files with
      Returns:
      all files matching the specified filter from the specified directory
    • readFile

      public static byte[] readFile(File file) throws IOException
      Returns the content of the specified file.
      Parameters:
      file - the file to read from
      Returns:
      the content of the specified file
      Throws:
      IOException - if an error occurs
    • writeFile

      public static void writeFile(File file, byte[] data) throws IOException
      Throws:
      IOException
    • copyDirectory

      public static boolean copyDirectory(File source, File dest) throws IOException
      Copies the content of the source directory in the specified directory. If the destination doesn't exist, it will be created. File is overwritten if already exist
      Throws:
      IOException
    • copyDirectory

      public static boolean copyDirectory(File source, File dest, boolean overwriteFile) throws IOException
      Copies the content of the source directory in the specified directory. If the destination doesn't exist, it will be created.
      Parameters:
      source - the source directory
      dest - the destination directory
      Returns:
      true if the copy successful
      Throws:
      IOException - if an error occurs during the copy
    • copyDirectory

      public static boolean copyDirectory(File source, File dest, String[] filters) throws IOException
      Copies the content of the source directory in the specified directory. If the destination doesn't exist, it will be created. File is overwritten if already exist
      Throws:
      IOException
    • copyDirectory

      public static boolean copyDirectory(File source, File dest, String[] filters, boolean overwriteFile) throws IOException
      Copies the content of the source directory in the specified directory. If the destination doesn't exist, it will be created.
      Parameters:
      source - the source directory
      dest - the destination directory
      filters - list of file extensions to copy, others are ignored. (e.g. "gif", "png", etc.)
      Returns:
      true if the copy successful
      Throws:
      IOException - if an error occurs during the copy
    • unzipFile

      public static boolean unzipFile(File source, File dest) throws IOException
      Unzips the content of the specified compressed file to the specified destination directory.
      Parameters:
      source - the compressed file
      dest - the destination directory.
      Returns:
      true if the operation completes successfully
      Throws:
      IOException - if an error occurs
    • zipDirectory

      public static boolean zipDirectory(File source, File dest, boolean recursive) throws IOException
      Zips the content of the specified directory to the specified destination file.
      Parameters:
      source - the source directory
      dest - the destination compressed file. If the file already exists, it will be overwritten.
      recursive - zip the content of the source directory recursively
      Returns:
      true if the operation completes successfully
      Throws:
      IOException - if an error occurs
    • zipDirectory

      public static boolean zipDirectory(File source, OutputStream stream, boolean recursive) throws IOException
      Throws:
      IOException
    • copyFile

      public static boolean copyFile(String source, String dest) throws IOException
      Copies the specifies source file to the destination file. File is overwritten if already exist
      Throws:
      IOException
    • copyFile

      public static boolean copyFile(String source, String dest, boolean overwrite) throws IOException
      Copies the specifies source file to the destination file.
      Parameters:
      source - the file to be copied
      dest - the destination file
      Returns:
      true if the operation completes successfully
      Throws:
      IOException - if an error occurs
    • copyFile

      public static boolean copyFile(File source, File dest) throws IOException
      Copies the specifies source file to the destination file. File is overwritten if already exist
      Throws:
      IOException
    • copyFile

      public static boolean copyFile(File source, File dest, boolean overwrite) throws IOException
      Copies the specifies source file to the destination file.
      Parameters:
      source - the file to be copied
      dest - the destination file
      Returns:
      true if the operation completes successfully
      Throws:
      IOException - if an error occurs
    • getDatedFileName

      public static String getDatedFileName()
      Returns the current date formatted like: '2002-04-17'. This is the standard used for every dated files created by JMapServer.
      Returns:
      the current date formatted like: '2002-04-17'.
    • deleteDirectory

      public static boolean deleteDirectory(File dir)
      Deletes a directory recursively
      Parameters:
      dir - the directory to delete
    • loadPropertiesFile

      public static Properties loadPropertiesFile(File file)
      Loads a Properties file.
      Parameters:
      file - the Properties file to load.
      Returns:
      a Properties object or null if an error occurred.
    • loadPropertiesFile

      public static Properties loadPropertiesFile(File file, Charset charset)
    • savePropertiesFile

      public static void savePropertiesFile(Properties prop, File fileName, String header)
    • getFileContent

      public static String getFileContent(File f) throws Exception
      Throws:
      Exception
    • setFileContent

      public static void setFileContent(File f, byte[] buffer) throws Exception
      Throws:
      Exception
    • setFileContent

      public static void setFileContent(File f, String buffer) throws Exception
      Throws:
      Exception
    • getJarAttributesFromManifest

      public static Attributes getJarAttributesFromManifest(File file) throws Exception
      Throws:
      Exception