Package htsjdk.samtools.util
Class IOUtil
java.lang.Object
htsjdk.samtools.util.IOUtil
Miscellaneous stateless static IO-oriented methods.
Also used for utility methods that wrap or aggregate functionality in Java IO.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Deprecated.Deprecated.Use since June 2019FileExtensions.BLOCK_COMPRESSED
instead.static final String
Deprecated.since June 2019 UseFileExtensions.COMPRESSED_VCF
instead.static final String
Deprecated.since June 2019 UseFileExtensions.COMPRESSED_VCF_INDEX
instead.static final String
Deprecated.since June 2019 UseFileExtensions.DICT
instead.static final long
static final int
number of bytes that will be read for the GZIP-header in the functionisGZIPInputStream(InputStream)
static final String
Deprecated.since June 2019 UseFileExtensions.INTERVAL_LIST
instead.static final long
static final String
Deprecated.since June 2019 UseFileExtensions.SAM
instead.static final int
Deprecated.UseDefaults.NON_ZERO_BUFFER_SIZE
instead.static final long
static final String[]
Deprecated.since June 2019 UseFileExtensions.VCF_LIST
instead.Deprecated.since June 2019 UseFileExtensions.VCF_LIST
instead.static final String
Deprecated.since June 2019 UseFileExtensions.VCF
instead.static final String
Deprecated.since June 2019 UseFileExtensions.VCF_INDEX
instead. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Path
addExtension
(Path path, String extension) Adds the extension to the given path.static void
Checks that a directory is non-null, extent, readable and a directory otherwise a runtime exception is thrown.static void
Checks that a directory is non-null, extent, writable and a directory otherwise a runtime exception is thrown.static void
Checks that a directory is non-null, extent, writable and a directory otherwise a runtime exception is thrown.static void
assertFileIsReadable
(File file) Checks that a file is non-null, exists, is not a directory and is readable.static void
assertFileIsReadable
(Path path) Checks that a file is non-null, exists, is not a directory and is readable.static void
assertFileIsWritable
(File file) Checks that a file is non-null, and is either extent and writable, or non-existent but that the parent directory exists and is writable.static void
assertFileIsWritable
(Path path) In some filesystems (e.g.static void
assertFilesAreReadable
(List<File> files) Checks that each file is non-null, exists, is not a directory and is readable.static void
assertFilesAreWritable
(List<File> files) Checks that each file is non-null, and is either extent and writable, or non-existent but that the parent directory exists and is writable.static void
assertFilesEqual
(File f1, File f2) Checks that the two files are the same length, and have the same content, otherwise throws a runtime exception.static void
assertFileSizeNonZero
(File file) Checks that a file is of non-zero lengthstatic void
assertInputIsValid
(String input) Checks that an input is is non-null, a URL or a file, exists, and if its a file then it is not a directory and is readable.static void
assertInputsAreValid
(List<String> inputs) Checks that each string is non-null, exists or is a URL, and if it is a file then not a directory and is readable.static void
assertPathsAreReadable
(List<Path> paths) Checks that each path is non-null, exists, is not a directory and is readable.static String
Returns the name of the file minus the extension (i.e.static void
copyDirectoryTree
(File fileOrDirectory, File destination) Copies a directory tree (all subdirectories and files) recursively to a destinationstatic void
Copy input to output, overwriting output if it already exists.static void
copyStream
(InputStream input, OutputStream output) Utility method to copy the contents of input to output.static Path
createTempDir
(String prefix) static File
createTempDir
(String prefix, String morePrefix) Deprecated.UsecreateTempDir(String)
instead.static boolean
deleteDirectoryTree
(File fileOrDirectory) Delete the given file or directory.static void
deleteFiles
(File... files) Delete a list of files, and write a warning message if one could not be deleted.static void
deleteFiles
(Iterable<File> files) static void
deleteOnExit
(Path path) Register aPath
for deletion on JVM exit.static void
deletePath
(Path path) Attempt to delete a single path and log an error if it is not deleted.static void
deletePaths
(Iterable<Path> paths) Iterate through Paths and delete each one.static void
deletePaths
(Path... paths) filesToPaths
(Collection<File> files) Takes a list of Files and converts them to a list of Paths Runs .toPath() on the contents of the input.static String
fileSuffix
(File f) Returns the name of the file extension (i.e.static int
static File
Returns a default tmp directory.static Path
Returns a default tmp directory as a Path.static File[]
getFilesMatchingRegexp
(File directory, String regexp) static File[]
getFilesMatchingRegexp
(File directory, Pattern regexp) static String
getFullCanonicalPath
(File file) Returns the full path to the file with all symbolic links resolvedstatic Path
Converts the given URI to aPath
object.static boolean
Checks if a file ends in one of theFileExtensions.BLOCK_COMPRESSED
.static boolean
hasBlockCompressedExtension
(String fileName) Checks if a file ends in one of theFileExtensions.BLOCK_COMPRESSED
.static boolean
Checks if a file ends in one of theFileExtensions.BLOCK_COMPRESSED
.static boolean
Checks if a path ends in one of theFileExtensions.BLOCK_COMPRESSED
.static boolean
hasGzipFileExtension
(Path path) check if the file name ends with .gz, .gzip, or .bfqstatic boolean
Check if the given URI has a scheme.static boolean
isBlockCompressed
(Path path) Checks if the provided path is block-compressed (including extension).static boolean
isBlockCompressed
(Path path, boolean checkExtension) Checks if the provided path is block-compressed.static boolean
isGZIPInputStream
(InputStream stream) Test whether a input stream looks like a GZIP input.static boolean
isRegularPath
(File file) static boolean
isRegularPath
(Path path) static boolean
Returns true iff the string is a url.static String
makeFileNameSafe
(String str) Takes a string and replaces any characters that are not safe for filenames with an underscorestatic SeekableStream
static SeekableStream
maybeBufferedSeekableStream
(SeekableStream stream, int bufferSize) static SeekableStream
static SeekableStream
static InputStream
static InputStream
maybeBufferInputStream
(InputStream is, int bufferSize) static OutputStream
static OutputStream
maybeBufferOutputStream
(OutputStream os, int bufferSize) static Reader
maybeBufferReader
(Reader reader) static Reader
maybeBufferReader
(Reader reader, int bufferSize) static Writer
maybeBufferWriter
(Writer writer) static Writer
maybeBufferWriter
(Writer writer, int bufferSize) static File
newTempFile
(String prefix, String suffix, File[] tmpDirs) Creates a new tmp file on one of the potential filesystems that has at least 5GB free.static File
newTempFile
(String prefix, String suffix, File[] tmpDirs, long minBytesFree) Creates a new tmp file on one of the available temp filesystems, registers it for deletion on JVM exit and then returns it.static Path
newTempPath
(String prefix, String suffix, Path[] tmpDirs) Creates a new tmp file on one of the potential filesystems that has at least 5GB free.static Path
newTempPath
(String prefix, String suffix, Path[] tmpDirs, long minBytesFree) Creates a new tmp path on one of the available temp filesystems, registers it for deletion on JVM exit and then returns it.static BufferedReader
Checks that a file exists and is readable, and then returns a buffered reader for it.static BufferedReader
Checks that a path exists and is readable, and then returns a buffered reader for it.static BufferedReader
Opens a file for reading, decompressing it if necessarystatic BufferedWriter
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O errorstatic BufferedWriter
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O errorstatic BufferedWriter
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O errorstatic BufferedWriter
openFileForBufferedWriting
(File file, boolean append) Preferred over PrintStream and PrintWriter because an exception is thrown on I/O errorstatic BufferedWriter
openFileForBufferedWriting
(Path path, OpenOption... openOptions) Preferred over PrintStream and PrintWriter because an exception is thrown on I/O errorstatic OutputStream
static OutputStream
static InputStream
openFileForReading
(File file) Opens a file for reading, decompressing it if necessarystatic InputStream
openFileForReading
(Path path) Opens a file for reading, decompressing it if necessarystatic OutputStream
openFileForWriting
(File file) Opens a file for writing, overwriting the file if it already existsstatic OutputStream
openFileForWriting
(File file, boolean append) Opens a file for writing, gzip it if it ends with ".gz" or "bfq"static OutputStream
openFileForWriting
(Path path, OpenOption... openOptions) Opens a file for writing, gzip it if it ends with ".gz" or "bfq"static InputStream
openGzipFileForReading
(File file) Opens a GZIP-encoded file for reading, decompressing it if necessarystatic InputStream
openGzipFileForReading
(Path path) Opens a GZIP-encoded file for reading, decompressing it if necessarystatic OutputStream
openGzipFileForWriting
(File file, boolean append) Opens a GZIP encoded file for writingstatic OutputStream
openGzipFileForWriting
(Path path, OpenOption... openOptions) Opens a GZIP encoded file for writingstatic String
readFully
(InputStream in) Reads everything from an input stream as characters and returns a single String.static IterableOnceIterator<String>
Returns an iterator over the lines in a text file.static void
recursiveDelete
(Path directory) Delete a directory and all files in it.static void
setCompressionLevel
(int compressionLevel) Sets the GZip compression level for subsequent GZIPOutputStream object creation.static long
sizeOfTree
(File fileOrDirectory) Returns the size (in bytes) of the file or directory and all it's children.static String
Convenience overload forslurp(java.io.InputStream, java.nio.charset.Charset)
using the default charsetCharset.defaultCharset()
.static String
slurp
(InputStream is) Convenience overload forslurp(java.io.InputStream, java.nio.charset.Charset)
using the default charsetCharset.defaultCharset()
.static String
slurp
(InputStream is, Charset charSet) Reads all of the stream into a String, decoding with the providedCharset
then closes the stream quietly.slurpLines
(File file) Returns all of the untrimmed lines in the provided file.static BufferedInputStream
toBufferedStream
(InputStream stream) Wrap the given stream in a BufferedInputStream, if it isn't already wrapperstatic Path
static void
transferByStream
(InputStream in, OutputStream out, long bytes) Transfers from the input stream to the output stream using stream operations and a buffer.unrollFiles
(Collection<File> inputs, String... extensions) Go through the files provided and if they have one of the provided file extensions pass the file into the output otherwise assume that file is a list of filenames and unfold it into the output.unrollPaths
(Collection<Path> inputs, String... extensions) Go through the files provided and if they have one of the provided file extensions pass the file to the output otherwise assume that file is a list of filenames and unfold it into the output (recursively).
-
Field Details
-
STANDARD_BUFFER_SIZE
Deprecated.UseDefaults.NON_ZERO_BUFFER_SIZE
instead. -
ONE_GB
public static final long ONE_GB- See Also:
-
TWO_GBS
public static final long TWO_GBS- See Also:
-
FIVE_GBS
public static final long FIVE_GBS- See Also:
-
VCF_FILE_EXTENSION
Deprecated.since June 2019 UseFileExtensions.VCF
instead.- See Also:
-
VCF_INDEX_EXTENSION
Deprecated.since June 2019 UseFileExtensions.VCF_INDEX
instead.- See Also:
-
BCF_FILE_EXTENSION
Deprecated.since June 2019 UseFileExtensions.BCF
instead.- See Also:
-
COMPRESSED_VCF_FILE_EXTENSION
Deprecated.since June 2019 UseFileExtensions.COMPRESSED_VCF
instead.- See Also:
-
COMPRESSED_VCF_INDEX_EXTENSION
Deprecated.since June 2019 UseFileExtensions.COMPRESSED_VCF_INDEX
instead.- See Also:
-
VCF_EXTENSIONS_LIST
Deprecated.since June 2019 UseFileExtensions.VCF_LIST
instead. -
VCF_EXTENSIONS
Deprecated.since June 2019 UseFileExtensions.VCF_LIST
instead.Possible extensions for VCF files and related formats. -
INTERVAL_LIST_FILE_EXTENSION
Deprecated.since June 2019 UseFileExtensions.INTERVAL_LIST
instead.- See Also:
-
SAM_FILE_EXTENSION
Deprecated.since June 2019 UseFileExtensions.SAM
instead.- See Also:
-
DICT_FILE_EXTENSION
Deprecated.since June 2019 UseFileExtensions.DICT
instead.- See Also:
-
BLOCK_COMPRESSED_EXTENSIONS
Deprecated.Use since June 2019FileExtensions.BLOCK_COMPRESSED
instead. -
GZIP_HEADER_READ_LENGTH
public static final int GZIP_HEADER_READ_LENGTHnumber of bytes that will be read for the GZIP-header in the functionisGZIPInputStream(InputStream)
- See Also:
-
-
Constructor Details
-
IOUtil
public IOUtil()
-
-
Method Details
-
setCompressionLevel
public static void setCompressionLevel(int compressionLevel) Sets the GZip compression level for subsequent GZIPOutputStream object creation.- Parameters:
compressionLevel
- 0 <= compressionLevel <= 9
-
getCompressionLevel
public static int getCompressionLevel() -
toBufferedStream
Wrap the given stream in a BufferedInputStream, if it isn't already wrapper- Parameters:
stream
- stream to be wrapped- Returns:
- A BufferedInputStream wrapping stream, or stream itself if stream instanceof BufferedInputStream.
-
transferByStream
Transfers from the input stream to the output stream using stream operations and a buffer. -
maybeBufferOutputStream
- Returns:
- If Defaults.BUFFER_SIZE > 0, wrap os in BufferedOutputStream, else return os itself.
-
maybeBufferOutputStream
- Returns:
- If bufferSize > 0, wrap os in BufferedOutputStream, else return os itself.
-
maybeBufferedSeekableStream
-
maybeBufferedSeekableStream
-
maybeBufferedSeekableStream
-
maybeBufferedSeekableStream
-
maybeBufferInputStream
- Returns:
- If Defaults.BUFFER_SIZE > 0, wrap is in BufferedInputStream, else return is itself.
-
maybeBufferInputStream
- Returns:
- If bufferSize > 0, wrap is in BufferedInputStream, else return is itself.
-
maybeBufferReader
-
maybeBufferReader
-
maybeBufferWriter
-
maybeBufferWriter
-
deleteFiles
Delete a list of files, and write a warning message if one could not be deleted.- Parameters:
files
- Files to be deleted.
-
deleteFiles
-
deletePaths
-
deletePaths
Iterate through Paths and delete each one. Note: Path is itself an Iterable. This method special cases that and deletes the single Path rather than Iterating the Path for targets to delete. - Parameters:
paths
- an iterable of Paths to delete
-
deletePath
Attempt to delete a single path and log an error if it is not deleted. -
isRegularPath
- Returns:
- true if the path is not a device (e.g. /dev/null or /dev/stdin), and is not an existing directory. I.e. is is a regular path that may correspond to an existing file, or a path that could be a regular output file.
-
isRegularPath
- Returns:
- true if the path is not a device (e.g. /dev/null or /dev/stdin), and is not an existing directory. I.e. is is a regular path that may correspond to an existing file, or a path that could be a regular output file.
-
newTempFile
public static File newTempFile(String prefix, String suffix, File[] tmpDirs, long minBytesFree) throws IOException Creates a new tmp file on one of the available temp filesystems, registers it for deletion on JVM exit and then returns it.- Throws:
IOException
-
newTempFile
Creates a new tmp file on one of the potential filesystems that has at least 5GB free.- Throws:
IOException
-
getDefaultTmpDir
Returns a default tmp directory. -
newTempPath
public static Path newTempPath(String prefix, String suffix, Path[] tmpDirs, long minBytesFree) throws IOException Creates a new tmp path on one of the available temp filesystems, registers it for deletion on JVM exit and then returns it.- Throws:
IOException
-
newTempPath
Creates a new tmp file on one of the potential filesystems that has at least 5GB free.- Throws:
IOException
-
getDefaultTmpDirPath
Returns a default tmp directory as a Path. -
deleteOnExit
Register aPath
for deletion on JVM exit.- See Also:
-
basename
Returns the name of the file minus the extension (i.e. text after the last "." in the filename). -
assertInputIsValid
Checks that an input is is non-null, a URL or a file, exists, and if its a file then it is not a directory and is readable. If any condition is false then a runtime exception is thrown.- Parameters:
input
- the input to check for validity
-
isUrl
Returns true iff the string is a url. Helps distinguish url inputs form file path inputs. -
assertFileIsReadable
Checks that a file is non-null, exists, is not a directory and is readable. If any condition is false then a runtime exception is thrown.- Parameters:
file
- the file to check for readability
-
assertFileIsReadable
Checks that a file is non-null, exists, is not a directory and is readable. If any condition is false then a runtime exception is thrown.- Parameters:
path
- the file to check for readability
-
assertFilesAreReadable
Checks that each file is non-null, exists, is not a directory and is readable. If any condition is false then a runtime exception is thrown.- Parameters:
files
- the list of files to check for readability
-
assertPathsAreReadable
Checks that each path is non-null, exists, is not a directory and is readable. If any condition is false then a runtime exception is thrown.- Parameters:
paths
- the list of paths to check for readability
-
assertInputsAreValid
Checks that each string is non-null, exists or is a URL, and if it is a file then not a directory and is readable. If any condition is false then a runtime exception is thrown.- Parameters:
inputs
- the list of files to check for readability
-
assertFileIsWritable
Checks that a file is non-null, and is either extent and writable, or non-existent but that the parent directory exists and is writable. If any condition is false then a runtime exception is thrown.- Parameters:
file
- the file to check for writability
-
assertFilesAreWritable
Checks that each file is non-null, and is either extent and writable, or non-existent but that the parent directory exists and is writable. If any condition is false then a runtime exception is thrown.- Parameters:
files
- the list of files to check for writability
-
assertFileIsWritable
In some filesystems (e.g. google cloud) it may not make sense to check writability. This method only checks writability when it's (i.e. for now when the path points to a file in the local filesystem) -
assertDirectoryIsWritable
Checks that a directory is non-null, extent, writable and a directory otherwise a runtime exception is thrown.- Parameters:
dir
- the dir to check for writability
-
assertDirectoryIsWritable
Checks that a directory is non-null, extent, writable and a directory otherwise a runtime exception is thrown.- Parameters:
dir
- the dir to check for writability
-
assertDirectoryIsReadable
Checks that a directory is non-null, extent, readable and a directory otherwise a runtime exception is thrown.- Parameters:
dir
- the dir to check for writability
-
assertFilesEqual
Checks that the two files are the same length, and have the same content, otherwise throws a runtime exception. -
assertFileSizeNonZero
Checks that a file is of non-zero length -
openFileForReading
Opens a file for reading, decompressing it if necessary- Parameters:
file
- The file to open- Returns:
- the input stream to read from
-
openFileForReading
Opens a file for reading, decompressing it if necessary- Parameters:
path
- The file to open- Returns:
- the input stream to read from
-
openGzipFileForReading
Opens a GZIP-encoded file for reading, decompressing it if necessary- Parameters:
file
- The file to open- Returns:
- the input stream to read from
-
openGzipFileForReading
Opens a GZIP-encoded file for reading, decompressing it if necessary- Parameters:
path
- The file to open- Returns:
- the input stream to read from
-
openFileForWriting
Opens a file for writing, overwriting the file if it already exists- Parameters:
file
- the file to write to- Returns:
- the output stream to write to
-
openFileForWriting
Opens a file for writing, gzip it if it ends with ".gz" or "bfq"- Parameters:
file
- the file to write toappend
- whether to append to the file if it already exists (we overwrite it if false)- Returns:
- the output stream to write to
-
openFileForWriting
Opens a file for writing, gzip it if it ends with ".gz" or "bfq"- Parameters:
path
- the file to write toopenOptions
- options to use when opening the file- Returns:
- the output stream to write to
-
hasGzipFileExtension
check if the file name ends with .gz, .gzip, or .bfq -
openFileForBufferedWriting
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error -
openFileForBufferedWriting
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error -
openFileForBufferedWriting
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error -
openFileForBufferedUtf8Writing
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error -
openFileForBufferedUtf8Writing
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error -
openFileForBufferedUtf8Reading
Opens a file for reading, decompressing it if necessary- Parameters:
file
- The file to open- Returns:
- the input stream to read from
-
openGzipFileForWriting
Opens a GZIP encoded file for writing- Parameters:
file
- the file to write toappend
- whether to append to the file if it already exists (we overwrite it if false)- Returns:
- the output stream to write to
-
openGzipFileForWriting
Opens a GZIP encoded file for writing- Parameters:
path
- the file to write toopenOptions
- options to control how the file is opened- Returns:
- the output stream to write to
-
openFileForMd5CalculatingWriting
-
openFileForMd5CalculatingWriting
-
copyStream
Utility method to copy the contents of input to output. The caller is responsible for opening and closing both streams.- Parameters:
input
- contents to be copiedoutput
- destination
-
copyFile
Copy input to output, overwriting output if it already exists. -
getFilesMatchingRegexp
- Parameters:
directory
-regexp
-- Returns:
- list of files matching regexp.
-
getFilesMatchingRegexp
-
deleteDirectoryTree
Delete the given file or directory. If a directory, all enclosing files and subdirs are also deleted. -
sizeOfTree
Returns the size (in bytes) of the file or directory and all it's children. -
copyDirectoryTree
Copies a directory tree (all subdirectories and files) recursively to a destination -
createTempDir
Deprecated.UsecreateTempDir(String)
instead. It turns out the mechanism was not "good enough" and caused security issues, the new implementation combines the prefix/morePrefix into a single prefix. The security flaw is fixed but due to the now extraneous morePrefix argument it is recommended to use the 1 argument form.Create a temporary subdirectory in the default temporary-file directory, using the given prefix and morePrefix to generate the name. Note that this method is not completely safe, because it create a temporary file, deletes it, and then creates a directory with the same name as the file. Should be good enough. This has been updated to avoid the problem in https://github.com/samtools/htsjdk/pull/1617- Parameters:
prefix
- The prefix string to be used in generating the file's name;morePrefix
- This was previously a suffix but the implementation changed; may be null, in which case the morePrefix ".tmp" will be used- Returns:
- File object for new directory
-
createTempDir
-
openFileForBufferedReading
Checks that a file exists and is readable, and then returns a buffered reader for it. -
openFileForBufferedReading
Checks that a path exists and is readable, and then returns a buffered reader for it. -
makeFileNameSafe
Takes a string and replaces any characters that are not safe for filenames with an underscore -
fileSuffix
Returns the name of the file extension (i.e. text after the last "." in the filename) including the . -
getFullCanonicalPath
Returns the full path to the file with all symbolic links resolved -
readFully
Reads everything from an input stream as characters and returns a single String. -
readLines
Returns an iterator over the lines in a text file. The underlying resources are automatically closed when the iterator hits the end of the input, or manually by calling close().- Parameters:
f
- a file that is to be read in as text- Returns:
- an iterator over the lines in the text file
-
slurpLines
Returns all of the untrimmed lines in the provided file.- Throws:
FileNotFoundException
-
slurpLines
- Throws:
FileNotFoundException
-
slurp
Convenience overload forslurp(java.io.InputStream, java.nio.charset.Charset)
using the default charsetCharset.defaultCharset()
.- Throws:
FileNotFoundException
-
slurp
Convenience overload forslurp(java.io.InputStream, java.nio.charset.Charset)
using the default charsetCharset.defaultCharset()
. -
slurp
Reads all of the stream into a String, decoding with the providedCharset
then closes the stream quietly. -
unrollFiles
Go through the files provided and if they have one of the provided file extensions pass the file into the output otherwise assume that file is a list of filenames and unfold it into the output. -
unrollPaths
Go through the files provided and if they have one of the provided file extensions pass the file to the output otherwise assume that file is a list of filenames and unfold it into the output (recursively). -
hasScheme
Check if the given URI has a scheme.- Parameters:
uriString
- the URI to check- Returns:
true
if the given URI has a scheme,false
if not, or if the URI is malformed.
-
getPath
Converts the given URI to aPath
object. If the filesystem cannot be found in the usual way, then attempt to load the filesystem provider using the thread context classloader. This is needed when the filesystem provider is loaded using a URL classloader (e.g. in spark-submit).- Parameters:
uriString
- the URI to convert- Returns:
- the resulting
Path
- Throws:
IOException
- an I/O error occurs creating the file system
-
getPaths
- Throws:
RuntimeIOException
-
toPath
-
filesToPaths
Takes a list of Files and converts them to a list of Paths Runs .toPath() on the contents of the input. -
isGZIPInputStream
Test whether a input stream looks like a GZIP input. This identifies both gzip and bgzip streams as being GZIP.- Parameters:
stream
- the input stream.- Returns:
- true if `stream` starts with a gzip signature.
- Throws:
IllegalArgumentException
- if `stream` cannot mark or reset the stream
-
addExtension
Adds the extension to the given path.- Parameters:
path
- the path to start from, eg. "/folder/file.jpg"extension
- the extension to add, eg. ".bak"- Returns:
- "/folder/file.jpg.bak"
-
isBlockCompressed
Checks if the provided path is block-compressed.Note that using
checkExtension=true
would avoid the cost of opening the file, but ifhasBlockCompressedExtension(String)
returnsfalse
this would not detect block-compressed files such BAM.- Parameters:
path
- file to check if it is block-compressed.checkExtension
- iftrue
, checks the extension before opening the file.- Returns:
true
if the file is block-compressed;false
otherwise.- Throws:
IOException
- if there is an I/O error.
-
isBlockCompressed
Checks if the provided path is block-compressed (including extension).Note that block-compressed file extensions
FileExtensions.BLOCK_COMPRESSED
are not checked by this method.- Parameters:
path
- file to check if it is block-compressed.- Returns:
true
if the file is block-compressed;false
otherwise.- Throws:
IOException
- if there is an I/O error.
-
hasBlockCompressedExtension
Checks if a file ends in one of theFileExtensions.BLOCK_COMPRESSED
.- Parameters:
fileName
- string name for the file. May be an HTTP/S url.- Returns:
true
if the file has a block-compressed extension;false
otherwise.
-
hasBlockCompressedExtension
Checks if a path ends in one of theFileExtensions.BLOCK_COMPRESSED
.- Parameters:
path
- object to extract the name from.- Returns:
true
if the path has a block-compressed extension;false
otherwise.
-
hasBlockCompressedExtension
Checks if a file ends in one of theFileExtensions.BLOCK_COMPRESSED
.- Parameters:
file
- object to extract the name from.- Returns:
true
if the file has a block-compressed extension;false
otherwise.
-
hasBlockCompressedExtension
Checks if a file ends in one of theFileExtensions.BLOCK_COMPRESSED
.- Parameters:
uri
- file as an URI.- Returns:
true
if the file has a block-compressed extension;false
otherwise.
-
recursiveDelete
Delete a directory and all files in it.- Parameters:
directory
- The directory to be deleted (along with its subdirectories)
-
FileExtensions.BCF
instead.