Package org.pathvisio.libgpml.util
Class FileUtils
java.lang.Object
org.pathvisio.libgpml.util.FileUtils
public class FileUtils
extends java.lang.Object
Collection of static utility methods dealing with files.
- Author:
- unknown
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
Modifier and Type Method Description static void
downloadFile(java.net.URL url, java.io.File toFile)
Downloads a remote file given by an URL to the given local filestatic java.lang.String
getExtension(java.lang.String fileName)
Returns file name extension.static java.util.List<java.io.File>
getFiles(java.io.File directory, boolean recursive)
Returns all files in a directorystatic java.util.List<java.io.File>
getFiles(java.io.File directory, java.lang.String extension, boolean recursive)
Returns all files in a directorystatic int
getNrLines(java.lang.String fileName)
Determines the number of lines in the given file.static java.io.File
mapFileTree(java.io.File f, java.io.File srcDir, java.io.File destDir)
Maps a file from one point in the directory tree to another point.static java.lang.String
removeExtension(java.lang.String fname)
Removes the file extension (everything from the last occurence of '.')static java.io.File
replaceExtension(java.io.File fname, java.lang.String extension)
Replaces file extension with something else.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
getFiles
public static java.util.List<java.io.File> getFiles(java.io.File directory, boolean recursive)Returns all files in a directory- Parameters:
directory
- The directory to get the files fromrecursive
- Whether to include sub directories or not- Returns:
- A list of files in the given directory
-
getFiles
public static java.util.List<java.io.File> getFiles(java.io.File directory, java.lang.String extension, boolean recursive)Returns all files in a directory- Parameters:
directory
- the directory to get the files fromextension
- the extension of the files to get, without the dot so e.g. "gpml"recursive
- whether to include subdirectories or not- Returns:
- A list of files with given extension present in the given directory
-
getNrLines
public static int getNrLines(java.lang.String fileName)Determines the number of lines in the given file.- Parameters:
fileName
- the file to get the number of lines from- Returns:
- the number of lines, or -1 if unable to determine the number of lines
-
getExtension
public static java.lang.String getExtension(java.lang.String fileName)Returns file name extension.- Parameters:
fileName
- file as a String- Returns:
- fragment of the filename after the '.'. Returns null if there was no '.'.
-
removeExtension
public static java.lang.String removeExtension(java.lang.String fname)Removes the file extension (everything from the last occurence of '.') -
replaceExtension
public static java.io.File replaceExtension(java.io.File fname, java.lang.String extension)Replaces file extension with something else. If there was no extension previously, the new one will simply be added.- Parameters:
fname
- the file name to use.extension
- the new extension to use. Should not include dot.
-
downloadFile
public static void downloadFile(java.net.URL url, java.io.File toFile) throws java.io.IOExceptionDownloads a remote file given by an URL to the given local file- Parameters:
url
- the URL that specifies the location of the file to downloadtoFile
- the local file to which the remote file will be downloaded- Throws:
java.io.IOException
-
mapFileTree
public static java.io.File mapFileTree(java.io.File f, java.io.File srcDir, java.io.File destDir)Maps a file from one point in the directory tree to another point. For example, with this function you can map from /home/username/input/pathways/human/metabolomic/pathway.gpml to /tmp/output/pathways/human/metabolomic/pathway.gpml- Parameters:
f
- the file.srcDir
- the source directory.destDir
- the destination directory.- Returns:
- the file.
-