Documentation of 'org.jgap.util.FileKit' Java class
FileKit
org.jgap.util

Class FileKit



  • public class FileKit
    extends java.lang.Object
    Contains helper functions related to the file system.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String fileseparator 
    • Constructor Summary

      Constructors 
      Constructor and Description
      FileKit() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.String addFilename(java.lang.String dir, java.lang.String a_filename) 
      static java.lang.String addSubDir(java.lang.String dir, java.lang.String subDir, boolean makeNice)
      Adds a subdir to a given dir and returns the resulting dir.
      static void copyFile(java.lang.String source, java.lang.String dest)
      Copies a complete file.
      static void copyFile(java.lang.String source, java.lang.String dest, int a_offset)
      Copies a file.
      static void createDirectory(java.lang.String a_dirname)
      Creates a directory, and if necessary, any of its parent directories.
      static boolean deleteDirectory(java.io.File a_dir)
      Deletes a directory from disk, also if it is non-empty.
      static boolean deleteFile(java.io.File a_file)
      Deletes a file from disk.
      static boolean deleteFile(java.lang.String a_filename)
      Deletes a file from disk.
      static boolean directoryExists(java.lang.String a_dir) 
      static boolean existsFile(java.lang.String a_filename) 
      static java.lang.String getConformPath(java.lang.String path) 
      static java.lang.String getConformPath(java.lang.String path, boolean makeNice) 
      static java.lang.String getConformPath(java.lang.String path, java.lang.String a_fileseparator) 
      static java.lang.String getCurrentDir() 
      static java.lang.String getFilename(java.lang.String name_and_path) 
      static java.lang.String getFilename(java.lang.String name_and_path, java.lang.String fileseparator)
      Extract file name from a given path+filename.
      static java.lang.String getJGAPVersion(java.util.jar.Manifest a_JGAPManifest) 
      static java.util.jar.Manifest getManifestOfJar(java.lang.String a_filename)
      Retrieve the manifest included in the given jar.
      static java.lang.String getModuleVersion(java.util.jar.Manifest a_JGAPManifest) 
      static java.lang.String getNiceURL(java.lang.String url, java.lang.String separator)
      Makes an URL nice by bringing it into a normalized (i.e.
      static java.lang.String getTempDir() 
      static java.lang.String getVersionOfJGAP(java.lang.String a_filename)
      See getJGAPVersion.
      static java.lang.String getVersionOfModule(java.lang.String a_filename)
      See getModuleVersion.
      static java.lang.String[] listFilesInDir(java.lang.String a_dir, java.lang.String a_mask)
      Returns the files within a directory that match a given pattern.
      static java.lang.ClassLoader loadJar(java.lang.String a_filename)
      Loads a jar file and returns a class loader to access the jar's classes.
      static java.util.Vector readFile(java.lang.String a_filename)
      Reads a text file.
      static java.lang.String removeDoubleSeparators(java.lang.String dir)
      Removes duplicate separators from an URL.
      static java.lang.String toJarFileName(java.lang.String a_filename)
      Converts an ordinary file name into a jar filename that can be used with JarClassLoader.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • fileseparator

        public static java.lang.String fileseparator
    • Constructor Detail

      • FileKit

        public FileKit()
    • Method Detail

      • copyFile

        public static void copyFile(java.lang.String source,
                                    java.lang.String dest)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException
        Copies a complete file.
        Parameters:
        source - source file name
        dest - destination file name or destination path (filename then taken from source)
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
        Since:
        3.2
      • copyFile

        public static void copyFile(java.lang.String source,
                                    java.lang.String dest,
                                    int a_offset)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException
        Copies a file.
        Parameters:
        source - source file name
        dest - destination file name or destination path (filename then taken from source)
        a_offset - start offset of file to copy (0 is begin of file)
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
        Since:
        3.2
      • getFilename

        public static java.lang.String getFilename(java.lang.String name_and_path)
      • getFilename

        public static java.lang.String getFilename(java.lang.String name_and_path,
                                                   java.lang.String fileseparator)
        Extract file name from a given path+filename.
        Parameters:
        name_and_path - input
        fileseparator - Slash or Backslash
        Returns:
        extracted file nmame
        Since:
        3.2
      • getCurrentDir

        public static java.lang.String getCurrentDir()
                                              throws java.io.IOException
        Returns:
        current directory of the application
        Throws:
        java.io.IOException
        Since:
        3.2
      • addSubDir

        public static java.lang.String addSubDir(java.lang.String dir,
                                                 java.lang.String subDir,
                                                 boolean makeNice)
        Adds a subdir to a given dir and returns the resulting dir.
        Parameters:
        dir - the original dir
        subDir - the subdir to add
        makeNice - true: call getNiceDir afterwards
        Returns:
        dir with subdir added
        Since:
        3.2
      • addFilename

        public static java.lang.String addFilename(java.lang.String dir,
                                                   java.lang.String a_filename)
      • getConformPath

        public static java.lang.String getConformPath(java.lang.String path,
                                                      boolean makeNice)
      • getConformPath

        public static java.lang.String getConformPath(java.lang.String path)
      • getConformPath

        public static java.lang.String getConformPath(java.lang.String path,
                                                      java.lang.String a_fileseparator)
      • getNiceURL

        public static java.lang.String getNiceURL(java.lang.String url,
                                                  java.lang.String separator)
        Makes an URL nice by bringing it into a normalized (i.e. convenient) form.
        Parameters:
        url - any URL
        separator - the separator to remove duplicates of
        Returns:
        prettified URL
        Since:
        3.2
      • removeDoubleSeparators

        public static java.lang.String removeDoubleSeparators(java.lang.String dir)
        Removes duplicate separators from an URL.
        Parameters:
        dir - name of directory including file name
        Returns:
        prettified URL
        Since:
        3.2
      • directoryExists

        public static boolean directoryExists(java.lang.String a_dir)
      • existsFile

        public static boolean existsFile(java.lang.String a_filename)
      • deleteFile

        public static boolean deleteFile(java.lang.String a_filename)
        Deletes a file from disk.
        Parameters:
        a_filename - name of file to delete
        Returns:
        true if deletion successful
      • deleteFile

        public static boolean deleteFile(java.io.File a_file)
        Deletes a file from disk.
        Parameters:
        a_file - name of file to delete
        Returns:
        true if deletion successful
        Since:
        3.4.3
      • deleteDirectory

        public static boolean deleteDirectory(java.io.File a_dir)
        Deletes a directory from disk, also if it is non-empty.
        Parameters:
        a_dir - name of file to delete
        Returns:
        true if deletion successful
        Since:
        3.4.3
      • loadJar

        public static java.lang.ClassLoader loadJar(java.lang.String a_filename)
                                             throws java.lang.Exception
        Loads a jar file and returns a class loader to access the jar's classes.
        Parameters:
        a_filename - the full jar file name, e.g.: C:/jgap/lib/ext/ashcroft.jar
        Returns:
        ClassLoader the class loader with which to access the loaded classes, e.g. by .loadClass(), e.g.: cl.loadClass("com.thoughtworks.ashcroft.runtime.JohnAshcroft");
        Throws:
        java.lang.Exception
        Since:
        3.2
      • getManifestOfJar

        public static java.util.jar.Manifest getManifestOfJar(java.lang.String a_filename)
                                                       throws java.lang.Exception
        Retrieve the manifest included in the given jar.
        Parameters:
        a_filename - jar file name
        Returns:
        Manifest included in the given jar
        Throws:
        java.lang.Exception
        Since:
        3.2
      • getJGAPVersion

        public static java.lang.String getJGAPVersion(java.util.jar.Manifest a_JGAPManifest)
        Parameters:
        a_JGAPManifest - manifest with JGAP-specific information
        Returns:
        version the jar file is working with (or version of the JGAP library in case the file _is_ the JGAP library)
        Since:
        3.2
      • getModuleVersion

        public static java.lang.String getModuleVersion(java.util.jar.Manifest a_JGAPManifest)
        Parameters:
        a_JGAPManifest - Manifest with JGAP-specific information
        Returns:
        version of the module represented by the jar
        Since:
        3.2
      • getVersionOfModule

        public static java.lang.String getVersionOfModule(java.lang.String a_filename)
                                                   throws java.lang.Exception
        See getModuleVersion.
        Parameters:
        a_filename - name of a JGAP jar
        Returns:
        version of the module represented by the jar
        Throws:
        java.lang.Exception
        Since:
        3.2
      • getVersionOfJGAP

        public static java.lang.String getVersionOfJGAP(java.lang.String a_filename)
                                                 throws java.lang.Exception
        See getJGAPVersion.
        Parameters:
        a_filename - name of a JGAP jar
        Returns:
        version the jar file is working wit (or version of the JGAP library in case the file *is* the JGAP library)
        Throws:
        java.lang.Exception
        Since:
        3.2
      • toJarFileName

        public static java.lang.String toJarFileName(java.lang.String a_filename)
        Converts an ordinary file name into a jar filename that can be used with JarClassLoader.
        Parameters:
        a_filename - the name to convert
        Returns:
        converted name
        Since:
        3.2
      • createDirectory

        public static void createDirectory(java.lang.String a_dirname)
                                    throws java.io.IOException
        Creates a directory, and if necessary, any of its parent directories.
        Parameters:
        a_dirname - name of the dir to create
        Throws:
        java.io.IOException
        Since:
        3.2
      • readFile

        public static java.util.Vector readFile(java.lang.String a_filename)
                                         throws java.io.IOException
        Reads a text file.
        Parameters:
        a_filename - name of text file
        Returns:
        list of read text lines
        Throws:
        java.io.IOException
        Since:
        3.2
      • getTempDir

        public static java.lang.String getTempDir()
        Returns:
        temporary directory
        Since:
        3.3.3
      • listFilesInDir

        public static java.lang.String[] listFilesInDir(java.lang.String a_dir,
                                                        java.lang.String a_mask)
                                                 throws java.lang.Exception
        Returns the files within a directory that match a given pattern. No directories are returned.
        Parameters:
        a_dir - String
        a_mask - String
        Returns:
        String[]
        Throws:
        java.lang.Exception
        Since:
        3.3.4

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.