Class FileTools
java.lang.Object
ubic.gemma.core.util.FileTools
Ported in-tree from
ubic.basecode.util.FileTools (baseCode project, Apache 2.0,
University of British Columbia). Trimmed to the methods used by Gemma; unused helpers
(file-extension predicates, line readers, string writers, touch, etc.) were dropped.- Author:
- keshav, Pavlidis, Will Braynen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringchompExtension(String filename) static StringcleanForFileName(String name) Avoid getting file names with spaces, slashes, quotes, # etc; replace them with "_".static FileCreates the directory if it does not exist.static intdeleteFiles(Collection<File> files) Deletes the specified collection of files.static InputStreamOpen a non-compressed, zipped, or gzipped file.static booleanstatic booleanstatic Collection<File> listDirectoryFiles(File directory) Given a File representing a directory, return the (non-directory) files it contains.static Collection<File> listSubDirectories(File directory) Given a File representing a directory, return the subdirectories it contains.static StringresourceToPath(String resourcePath) Resolve a classpath resource to an absolute filesystem path.static StringunGzipFile(String seekFile) Given the path to a gzipped file, unzip it into the same directory.static Collection<File> unZipFiles(String seekFile) Unzip every entry of a zip archive next to the archive.
-
Constructor Details
-
FileTools
public FileTools()
-
-
Method Details
-
chompExtension
-
cleanForFileName
Avoid getting file names with spaces, slashes, quotes, # etc; replace them with "_".- Throws:
IllegalArgumentException- if the resulting string is empty, or if the input is blank.
-
createDir
-
deleteFiles
Deletes the specified collection of files.- Returns:
- int The number of files deleted.
- See Also:
-
getInputStreamFromPlainOrCompressedFile
public static InputStream getInputStreamFromPlainOrCompressedFile(String fileName) throws IOException, FileNotFoundException Open a non-compressed, zipped, or gzipped file. Uses the file name pattern to figure this out.- Parameters:
fileName- if zipped, only the first file in the archive is used.- Throws:
IOExceptionFileNotFoundException
-
isGZipped
- Returns:
- true if the filename ends with
.gzor.gzip(case-insensitive).
-
isZipped
- Returns:
- true if the filename ends with
.zip(case-insensitive).
-
listDirectoryFiles
Given a File representing a directory, return the (non-directory) files it contains. -
listSubDirectories
Given a File representing a directory, return the subdirectories it contains. -
resourceToPath
Resolve a classpath resource to an absolute filesystem path.- Throws:
URISyntaxException
-
unGzipFile
Given the path to a gzipped file, unzip it into the same directory. If the output file already exists it will be overwritten.- Returns:
- absolute path to the unzipped file.
- Throws:
IOException
-
unZipFiles
Unzip every entry of a zip archive next to the archive.- Throws:
IOException
-