Package blbutil

Class FileUtil


  • public class FileUtil
    extends java.lang.Object
    Class FileUtil contains static methods for working with files.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.PrintWriter bgzipPrintWriter​(java.io.File file)
      Returns a buffered java.io.PrintWriter that compresses data using the BGZIP algorithm and writes the compressed data to the specified file.
      static java.io.PrintWriter bgzipPrintWriter​(java.io.File file, boolean append)
      Returns a buffered java.io.PrintWriter that compresses data using the BGZIP algorithm and writes the compressed data to the specified file.
      static java.io.InputStream bufferedInputStream​(java.io.File file)
      Returns an buffered java.io.InputStream with default buffer size reading from the specified file.
      static java.io.OutputStream bufferedOutputStream​(java.io.File file)
      Returns an buffered java.io.OutputStream with default buffer size writing to the specified file.
      static java.io.OutputStream bufferedOutputStream​(java.io.File file, boolean append)
      Returns an buffered java.io.OutputStream with default buffer size writing to the specified file.
      static java.io.PrintWriter gzipPrintWriter​(java.io.File file)
      Returns a buffered java.io.PrintWriter writing to the specified file.
      static java.io.PrintWriter gzipPrintWriter​(java.io.File file, boolean append)
      Returns a buffered java.io.PrintWriter writing to the specified file.
      static java.io.PrintWriter nonBufferedPrintWriter​(java.io.File file, boolean append)
      Returns an unbuffered java.io.PrintWriter writing to the specified file.
      static java.io.PrintWriter printWriter​(java.io.File file)
      Returns a buffered java.io.PrintWriter writing to the specified file.
      static java.io.PrintWriter printWriter​(java.io.File file, boolean append)
      Returns a buffered java.io.PrintWriter writing to the specified file.
      static java.io.RandomAccessFile randomAccessFile​(java.io.File file, java.lang.String mode)
      Returns a java.io.RandomAccessFile to read from or optionally to write to the specified file.
      static java.io.PrintWriter stdOutPrintWriter()
      Returns a java.io.PrintWriter that writes to standard out.
      static java.io.File tempFile​(java.lang.String prefix)
      Returns a temporary File that will be deleted when the Java virtual machine exits.
      static java.io.File tempFile​(java.lang.String prefix, java.io.File directory)
      Creates and returns a new empty temporary file in the specified directory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • tempFile

        public static java.io.File tempFile​(java.lang.String prefix,
                                            java.io.File directory)
        Creates and returns a new empty temporary file in the specified directory. The temporary file will be deleted when the JVM terminates if the JVM terminates normally.
        Parameters:
        prefix - a prefix of at least 3 characters for the temporary filename
        directory - the directory in which the temporary file is to be created.
        Returns:
        a new empty temporary file in the specified directory.
        Throws:
        java.lang.NullPointerException - if prefix == null || directory == null
      • randomAccessFile

        public static java.io.RandomAccessFile randomAccessFile​(java.io.File file,
                                                                java.lang.String mode)
        Returns a java.io.RandomAccessFile to read from or optionally to write to the specified file. If the input stream cannot be opened, an error message will be printed and the java interpreter will exit.
        Parameters:
        file - a file
        mode - the access mode as described in the documentation for the java.io.RandomAccessFile constructors
        Returns:
        a java.io.RandomAccessFile
        Throws:
        java.lang.NullPointerException - if file == null || mode == null
      • bufferedInputStream

        public static java.io.InputStream bufferedInputStream​(java.io.File file)
        Returns an buffered java.io.InputStream with default buffer size reading from the specified file. If the input stream cannot be opened, an error message will be printed and the java interpreter will exit.
        Parameters:
        file - a file
        Returns:
        an buffered java.io.InputStream
        Throws:
        java.lang.NullPointerException - if file == null
      • bufferedOutputStream

        public static java.io.OutputStream bufferedOutputStream​(java.io.File file)
        Returns an buffered java.io.OutputStream with default buffer size writing to the specified file. If the file cannot be opened for writing, an error message will be printed and the Java Virtual Machine will exit.
        Parameters:
        file - a file
        Returns:
        a buffered java.io.OutputStream
        Throws:
        java.lang.NullPointerException - if file == null
      • bufferedOutputStream

        public static java.io.OutputStream bufferedOutputStream​(java.io.File file,
                                                                boolean append)
        Returns an buffered java.io.OutputStream with default buffer size writing to the specified file. If the file cannot be opened for writing, an error message will be printed and the Java Virtual Machine will exit. If the specified file exists and append is false, bytes written by the returned java.io.OutputStream will overwrite the previously existing file.
        Parameters:
        file - a file
        append - true if bytes will be appended to the end of the file
        Returns:
        an buffered java.io.OutputStream
        Throws:
        java.lang.NullPointerException - if file == null
      • stdOutPrintWriter

        public static java.io.PrintWriter stdOutPrintWriter()
        Returns a java.io.PrintWriter that writes to standard out.
        Returns:
        a java.io.PrintWriter that writes to standard out
      • gzipPrintWriter

        public static java.io.PrintWriter gzipPrintWriter​(java.io.File file)
        Returns a buffered java.io.PrintWriter writing to the specified file. The resulting file will be compressed using the GZIP compression algorithm. If the file cannot be opened, an error message will be printed and the java interpreter will exit. If the specified file exists, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        Returns:
        a java.io.PrintWriter writing to the specified file
        Throws:
        java.lang.NullPointerException - if file == null
      • gzipPrintWriter

        public static java.io.PrintWriter gzipPrintWriter​(java.io.File file,
                                                          boolean append)
        Returns a buffered java.io.PrintWriter writing to the specified file. The resulting file will be compressed using the GZIP compression algorithm. If the file cannot be opened, an error message will be printed and the java interpreter will exit. If the specified file exists and append is false, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        append - true if bytes will be appended to the end of the file
        Returns:
        a java.io.PrintWriter writing to the specified file
        Throws:
        java.lang.NullPointerException - if file == null
      • bgzipPrintWriter

        public static java.io.PrintWriter bgzipPrintWriter​(java.io.File file)
        Returns a buffered java.io.PrintWriter that compresses data using the BGZIP algorithm and writes the compressed data to the specified file. The close() method of the returned PrintWriter will write an empty BGZIP block to the end of the output stream. If the file cannot be opened for writing, an error message will be printed and the Java Virtual Machine will exit. If the specified file exists, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        Returns:
        a buffered java.io.PrintWriter
        Throws:
        java.lang.NullPointerException - if file == null
      • bgzipPrintWriter

        public static java.io.PrintWriter bgzipPrintWriter​(java.io.File file,
                                                           boolean append)
        Returns a buffered java.io.PrintWriter that compresses data using the BGZIP algorithm and writes the compressed data to the specified file. The close() method of the returned PrintWriter will write an empty BGZIP block to the end of the output stream. If the file cannot be opened for writing, an error message will be printed and the Java Virtual Machine will exit. If the specified file exists and append is false, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        append - true if bytes will be appended to the end of the file
        Returns:
        a buffered java.io.PrintWriter
        Throws:
        java.lang.NullPointerException - if file == null
      • printWriter

        public static java.io.PrintWriter printWriter​(java.io.File file)
        Returns a buffered java.io.PrintWriter writing to the specified file. If the file cannot be opened, an error message will be printed and the Java Virtual Machine will exit. If the specified file exists, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        Returns:
        a buffered java.io.PrintWriter writing to the specified file
        Throws:
        java.lang.NullPointerException - if file == null
      • printWriter

        public static java.io.PrintWriter printWriter​(java.io.File file,
                                                      boolean append)
        Returns a buffered java.io.PrintWriter writing to the specified file. If the file cannot be opened, an error message will be printed and the Java Virtual Machine will exit. If the specified file exists and append is false, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        append - true if the data will be appended to the end of any existing file
        Returns:
        a buffered java.io.PrintWriter writing to the specified file
        Throws:
        java.lang.NullPointerException - if file == null
      • nonBufferedPrintWriter

        public static java.io.PrintWriter nonBufferedPrintWriter​(java.io.File file,
                                                                 boolean append)
        Returns an unbuffered java.io.PrintWriter writing to the specified file. If the file cannot be opened, an error message will be printed and the Java Virtual Machine will exit. If the specified file exists and append is false, bytes written by the returned PrintWriter will overwrite the previously existing file.
        Parameters:
        file - a file
        append - true if the data will be appended to the end of any existing file
        Returns:
        a non-buffered java.io.PrintWriter writing to the specified file
        Throws:
        java.lang.NullPointerException - if file == null
      • tempFile

        public static java.io.File tempFile​(java.lang.String prefix)
        Returns a temporary File that will be deleted when the Java virtual machine exits.
        Parameters:
        prefix - the filename prefix.
        Returns:
        a File a new empty file.
        Throws:
        java.lang.IllegalArgumentException - if prefix contains fewer than three characters