org.jgap.util
Class FileKit
- java.lang.Object
-
- org.jgap.util.FileKit
-
public class FileKit extends java.lang.ObjectContains helper functions related to the file system.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.Stringfileseparator
-
Constructor Summary
Constructors Constructor and Description FileKit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.lang.StringaddFilename(java.lang.String dir, java.lang.String a_filename)static java.lang.StringaddSubDir(java.lang.String dir, java.lang.String subDir, boolean makeNice)Adds a subdir to a given dir and returns the resulting dir.static voidcopyFile(java.lang.String source, java.lang.String dest)Copies a complete file.static voidcopyFile(java.lang.String source, java.lang.String dest, int a_offset)Copies a file.static voidcreateDirectory(java.lang.String a_dirname)Creates a directory, and if necessary, any of its parent directories.static booleandeleteDirectory(java.io.File a_dir)Deletes a directory from disk, also if it is non-empty.static booleandeleteFile(java.io.File a_file)Deletes a file from disk.static booleandeleteFile(java.lang.String a_filename)Deletes a file from disk.static booleandirectoryExists(java.lang.String a_dir)static booleanexistsFile(java.lang.String a_filename)static java.lang.StringgetConformPath(java.lang.String path)static java.lang.StringgetConformPath(java.lang.String path, boolean makeNice)static java.lang.StringgetConformPath(java.lang.String path, java.lang.String a_fileseparator)static java.lang.StringgetCurrentDir()static java.lang.StringgetFilename(java.lang.String name_and_path)static java.lang.StringgetFilename(java.lang.String name_and_path, java.lang.String fileseparator)Extract file name from a given path+filename.static java.lang.StringgetJGAPVersion(java.util.jar.Manifest a_JGAPManifest)static java.util.jar.ManifestgetManifestOfJar(java.lang.String a_filename)Retrieve the manifest included in the given jar.static java.lang.StringgetModuleVersion(java.util.jar.Manifest a_JGAPManifest)static java.lang.StringgetNiceURL(java.lang.String url, java.lang.String separator)Makes an URL nice by bringing it into a normalized (i.e.static java.lang.StringgetTempDir()static java.lang.StringgetVersionOfJGAP(java.lang.String a_filename)See getJGAPVersion.static java.lang.StringgetVersionOfModule(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.ClassLoaderloadJar(java.lang.String a_filename)Loads a jar file and returns a class loader to access the jar's classes.static java.util.VectorreadFile(java.lang.String a_filename)Reads a text file.static java.lang.StringremoveDoubleSeparators(java.lang.String dir)Removes duplicate separators from an URL.static java.lang.StringtoJarFileName(java.lang.String a_filename)Converts an ordinary file name into a jar filename that can be used with JarClassLoader.
-
-
-
Method Detail
-
copyFile
public static void copyFile(java.lang.String source, java.lang.String dest) throws java.io.FileNotFoundException, java.io.IOExceptionCopies a complete file.- Parameters:
source- source file namedest- destination file name or destination path (filename then taken from source)- Throws:
java.io.FileNotFoundExceptionjava.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.IOExceptionCopies a file.- Parameters:
source- source file namedest- 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.FileNotFoundExceptionjava.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- inputfileseparator- 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 dirsubDir- the subdir to addmakeNice- 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 URLseparator- 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.ExceptionLoads 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.ExceptionRetrieve 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.ExceptionSee 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.ExceptionSee 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.IOExceptionCreates 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.IOExceptionReads 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.ExceptionReturns the files within a directory that match a given pattern. No directories are returned.- Parameters:
a_dir- Stringa_mask- String- Returns:
- String[]
- Throws:
java.lang.Exception- Since:
- 3.3.4
-
-
DMelt 3.0 © DataMelt by jWork.ORG