Class FileTools

java.lang.Object
ubic.gemma.core.util.FileTools

public class FileTools extends Object
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 Details

    • FileTools

      public FileTools()
  • Method Details

    • chompExtension

      public static String chompExtension(String filename)
      Returns:
      the filename with its final extension stripped (everything after the last '.'), or the original filename if no extension is present.
    • cleanForFileName

      public static String cleanForFileName(String name)
      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

      public static File createDir(String directory)
      Creates the directory if it does not exist.
    • deleteFiles

      public static int deleteFiles(Collection<File> files)
      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:
      IOException
      FileNotFoundException
    • isGZipped

      public static boolean isGZipped(String fileName)
      Returns:
      true if the filename ends with .gz or .gzip (case-insensitive).
    • isZipped

      public static boolean isZipped(String filename)
      Returns:
      true if the filename ends with .zip (case-insensitive).
    • listDirectoryFiles

      public static Collection<File> listDirectoryFiles(File directory)
      Given a File representing a directory, return the (non-directory) files it contains.
    • listSubDirectories

      public static Collection<File> listSubDirectories(File directory)
      Given a File representing a directory, return the subdirectories it contains.
    • resourceToPath

      public static String resourceToPath(String resourcePath) throws URISyntaxException
      Resolve a classpath resource to an absolute filesystem path.
      Throws:
      URISyntaxException
    • unGzipFile

      public static String unGzipFile(String seekFile) throws IOException
      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

      public static Collection<File> unZipFiles(String seekFile) throws IOException
      Unzip every entry of a zip archive next to the archive.
      Throws:
      IOException