Package blbutil
Class FileUtil
java.lang.Object
blbutil.FileUtil
Class
FileUtil contains static methods for working with files.-
Method Summary
Modifier and TypeMethodDescriptionstatic PrintWriterbgzipPrintWriter(File file) Returns a bufferedjava.io.PrintWriterthat compresses data using the BGZIP algorithm and writes the compressed data to the specified file.static PrintWriterbgzipPrintWriter(File file, boolean append) Returns a bufferedjava.io.PrintWriterthat compresses data using the BGZIP algorithm and writes the compressed data to the specified file.static InputStreambufferedInputStream(File file) Returns an bufferedjava.io.InputStreamwith default buffer size reading from the specified file.static OutputStreambufferedOutputStream(File file) Returns an bufferedjava.io.OutputStreamwith default buffer size writing to the specified file.static OutputStreambufferedOutputStream(File file, boolean append) Returns an bufferedjava.io.OutputStreamwith default buffer size writing to the specified file.static PrintWritergzipPrintWriter(File file) Returns a bufferedjava.io.PrintWriterwriting to the specified file.static PrintWritergzipPrintWriter(File file, boolean append) Returns a bufferedjava.io.PrintWriterwriting to the specified file.static PrintWriternonBufferedPrintWriter(File file, boolean append) Returns an unbufferedjava.io.PrintWriterwriting to the specified file.static PrintWriterprintWriter(File file) Returns a bufferedjava.io.PrintWriterwriting to the specified file.static PrintWriterprintWriter(File file, boolean append) Returns a bufferedjava.io.PrintWriterwriting to the specified file.static RandomAccessFilerandomAccessFile(File file, String mode) Returns ajava.io.RandomAccessFileto read from or optionally to write to the specified file.static voidskipNBytes(InputStream is, long nBytes, String source) Skips and discards the specified number of bytes of data from the specified input stream.static PrintWriterReturns ajava.io.PrintWriterthat writes to standard out.static FileReturns a temporaryFilethat will be deleted when the Java virtual machine exits.static FileCreates and returns a new empty temporary file in the specified directory.
-
Method Details
-
randomAccessFile
Returns ajava.io.RandomAccessFileto 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 filemode- the access mode as described in the documentation for thejava.io.RandomAccessFileconstructors- Returns:
- a
java.io.RandomAccessFile - Throws:
NullPointerException- iffile == null || mode == null
-
bufferedInputStream
Returns an bufferedjava.io.InputStreamwith 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:
NullPointerException- iffile == null
-
bufferedOutputStream
Returns an bufferedjava.io.OutputStreamwith 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:
NullPointerException- iffile == null
-
bufferedOutputStream
Returns an bufferedjava.io.OutputStreamwith 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 andappendisfalse, bytes written by the returnedjava.io.OutputStreamwill overwrite the previously existing file.- Parameters:
file- a fileappend-trueif bytes will be appended to the end of the file- Returns:
- an buffered
java.io.OutputStream - Throws:
NullPointerException- iffile == null
-
stdOutPrintWriter
Returns ajava.io.PrintWriterthat writes to standard out.- Returns:
- a
java.io.PrintWriterthat writes to standard out
-
gzipPrintWriter
Returns a bufferedjava.io.PrintWriterwriting 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 returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a file- Returns:
- a
java.io.PrintWriterwriting to the specified file - Throws:
NullPointerException- iffile == null
-
gzipPrintWriter
Returns a bufferedjava.io.PrintWriterwriting 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 andappendisfalse, bytes written by the returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a fileappend-trueif bytes will be appended to the end of the file- Returns:
- a
java.io.PrintWriterwriting to the specified file - Throws:
NullPointerException- iffile == null
-
bgzipPrintWriter
Returns a bufferedjava.io.PrintWriterthat compresses data using the BGZIP algorithm and writes the compressed data to the specified file. Theclose()method of the returnedPrintWriterwill 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 returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a file- Returns:
- a buffered
java.io.PrintWriter - Throws:
NullPointerException- iffile == null
-
bgzipPrintWriter
Returns a bufferedjava.io.PrintWriterthat compresses data using the BGZIP algorithm and writes the compressed data to the specified file. Theclose()method of the returnedPrintWriterwill 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 andappendisfalse, bytes written by the returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a fileappend-trueif bytes will be appended to the end of the file- Returns:
- a buffered
java.io.PrintWriter - Throws:
NullPointerException- iffile == null
-
printWriter
Returns a bufferedjava.io.PrintWriterwriting 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 returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a file- Returns:
- a buffered
java.io.PrintWriterwriting to the specified file - Throws:
NullPointerException- iffile == null
-
printWriter
Returns a bufferedjava.io.PrintWriterwriting 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 andappendisfalse, bytes written by the returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a fileappend-trueif the data will be appended to the end of any existing file- Returns:
- a buffered
java.io.PrintWriterwriting to the specified file - Throws:
NullPointerException- iffile == null
-
nonBufferedPrintWriter
Returns an unbufferedjava.io.PrintWriterwriting 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 andappendisfalse, bytes written by the returnedPrintWriterwill overwrite the previously existing file.- Parameters:
file- a fileappend-trueif the data will be appended to the end of any existing file- Returns:
- a non-buffered
java.io.PrintWriterwriting to the specified file - Throws:
NullPointerException- iffile == null
-
skipNBytes
Skips and discards the specified number of bytes of data from the specified input stream. No bytes are skipped if the specified number of bytes is negative or 0. The method blocks until the specified number of bytes have been skipped or anIOExceptionexception is thrown. The Java Virtual Machine will exit with an error message if the end of file is reached before the specified number of bytes are skipped or if anIOExceptionis thrown.- Parameters:
is- an input streamnBytes- the number of bytes to skipsource- a string description of the input stream source
-
tempFile
Returns a temporaryFilethat will be deleted when the Java virtual machine exits.- Parameters:
prefix- the filename prefix.- Returns:
- a
Filea new empty file. - Throws:
IllegalArgumentException- ifprefixcontains fewer than three characters
-
tempFile
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 filenamedirectory- the directory in which the temporary file is to be created.- Returns:
- a new empty temporary file in the specified directory.
- Throws:
NullPointerException- ifprefix == null || directory == null
-