public class IOUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BCF_FILE_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.BCF instead. |
static java.util.Set<java.lang.String> |
BLOCK_COMPRESSED_EXTENSIONS
Deprecated.
Use since June 2019
FileExtensions.BLOCK_COMPRESSED instead. |
static java.lang.String |
COMPRESSED_VCF_FILE_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.COMPRESSED_VCF instead. |
static java.lang.String |
COMPRESSED_VCF_INDEX_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.COMPRESSED_VCF_INDEX instead. |
static java.lang.String |
DICT_FILE_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.DICT instead. |
static long |
FIVE_GBS |
static int |
GZIP_HEADER_READ_LENGTH
number of bytes that will be read for the GZIP-header in the function
isGZIPInputStream(InputStream) |
static java.lang.String |
INTERVAL_LIST_FILE_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.INTERVAL_LIST instead. |
static long |
ONE_GB |
static java.lang.String |
SAM_FILE_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.SAM instead. |
static int |
STANDARD_BUFFER_SIZE
Deprecated.
Use
Defaults.NON_ZERO_BUFFER_SIZE instead. |
static long |
TWO_GBS |
static java.lang.String[] |
VCF_EXTENSIONS
Deprecated.
since June 2019 Use
FileExtensions.VCF_LIST instead. |
static java.util.List<java.lang.String> |
VCF_EXTENSIONS_LIST
Deprecated.
since June 2019 Use
FileExtensions.VCF_LIST instead. |
static java.lang.String |
VCF_FILE_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.VCF instead. |
static java.lang.String |
VCF_INDEX_EXTENSION
Deprecated.
since June 2019 Use
FileExtensions.VCF_INDEX instead. |
Constructor and Description |
---|
IOUtil() |
Modifier and Type | Method and Description |
---|---|
static java.nio.file.Path |
addExtension(java.nio.file.Path path,
java.lang.String extension)
Adds the extension to the given path.
|
static void |
assertDirectoryIsReadable(java.io.File dir)
Checks that a directory is non-null, extent, readable and a directory
otherwise a runtime exception is thrown.
|
static void |
assertDirectoryIsWritable(java.io.File dir)
Checks that a directory is non-null, extent, writable and a directory
otherwise a runtime exception is thrown.
|
static void |
assertDirectoryIsWritable(java.nio.file.Path dir)
Checks that a directory is non-null, extent, writable and a directory
otherwise a runtime exception is thrown.
|
static void |
assertFileIsReadable(java.io.File file)
Checks that a file is non-null, exists, is not a directory and is readable.
|
static void |
assertFileIsReadable(java.nio.file.Path path)
Checks that a file is non-null, exists, is not a directory and is readable.
|
static void |
assertFileIsWritable(java.io.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 |
assertFilesAreReadable(java.util.List<java.io.File> files)
Checks that each file is non-null, exists, is not a directory and is readable.
|
static void |
assertFilesAreWritable(java.util.List<java.io.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(java.io.File f1,
java.io.File f2)
Checks that the two files are the same length, and have the same content, otherwise throws a runtime exception.
|
static void |
assertFileSizeNonZero(java.io.File file)
Checks that a file is of non-zero length
|
static void |
assertInputIsValid(java.lang.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(java.util.List<java.lang.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(java.util.List<java.nio.file.Path> paths)
Checks that each path is non-null, exists, is not a directory and is readable.
|
static java.lang.String |
basename(java.io.File f)
Returns the name of the file minus the extension (i.e.
|
static void |
copyDirectoryTree(java.io.File fileOrDirectory,
java.io.File destination)
Copies a directory tree (all subdirectories and files) recursively to a destination
|
static void |
copyFile(java.io.File input,
java.io.File output)
Copy input to output, overwriting output if it already exists.
|
static void |
copyStream(java.io.InputStream input,
java.io.OutputStream output)
Utility method to copy the contents of input to output.
|
static java.io.File |
createTempDir(java.lang.String prefix,
java.lang.String suffix)
Create a temporary subdirectory in the default temporary-file directory, using the given prefix and suffix to generate the name.
|
static boolean |
deleteDirectoryTree(java.io.File fileOrDirectory)
Delete the given file or directory.
|
static void |
deleteFiles(java.io.File... files)
Delete a list of files, and write a warning message if one could not be deleted.
|
static void |
deleteFiles(java.lang.Iterable<java.io.File> files) |
static void |
deleteOnExit(java.nio.file.Path path)
Register a
Path for deletion on JVM exit. |
static void |
deletePath(java.nio.file.Path path)
Attempt to delete a single path and log an error if it is not deleted.
|
static void |
deletePaths(java.lang.Iterable<java.nio.file.Path> paths)
Iterate through Paths and delete each one.
|
static void |
deletePaths(java.nio.file.Path... paths) |
static java.util.List<java.nio.file.Path> |
filesToPaths(java.util.Collection<java.io.File> files)
Takes a list of Files and converts them to a list of Paths
Runs .toPath() on the contents of the input.
|
static java.lang.String |
fileSuffix(java.io.File f)
Returns the name of the file extension (i.e.
|
static int |
getCompressionLevel() |
static java.io.File |
getDefaultTmpDir()
Returns a default tmp directory.
|
static java.nio.file.Path |
getDefaultTmpDirPath()
Returns a default tmp directory as a Path.
|
static java.io.File[] |
getFilesMatchingRegexp(java.io.File directory,
java.util.regex.Pattern regexp) |
static java.io.File[] |
getFilesMatchingRegexp(java.io.File directory,
java.lang.String regexp) |
static java.lang.String |
getFullCanonicalPath(java.io.File file)
Returns the full path to the file with all symbolic links resolved
|
static java.nio.file.Path |
getPath(java.lang.String uriString)
Converts the given URI to a
Path object. |
static java.util.List<java.nio.file.Path> |
getPaths(java.util.List<java.lang.String> uriStrings) |
static boolean |
hasBlockCompressedExtension(java.io.File file)
Checks if a file ends in one of the
FileExtensions.BLOCK_COMPRESSED . |
static boolean |
hasBlockCompressedExtension(java.nio.file.Path path)
Checks if a path ends in one of the
FileExtensions.BLOCK_COMPRESSED . |
static boolean |
hasBlockCompressedExtension(java.lang.String fileName)
Checks if a file ends in one of the
FileExtensions.BLOCK_COMPRESSED . |
static boolean |
hasBlockCompressedExtension(java.net.URI uri)
Checks if a file ends in one of the
FileExtensions.BLOCK_COMPRESSED . |
static boolean |
hasGzipFileExtension(java.nio.file.Path path)
check if the file name ends with .gz, .gzip, or .bfq
|
static boolean |
hasScheme(java.lang.String uriString)
Check if the given URI has a scheme.
|
static boolean |
isBlockCompressed(java.nio.file.Path path)
Checks if the provided path is block-compressed (including extension).
|
static boolean |
isBlockCompressed(java.nio.file.Path path,
boolean checkExtension)
Checks if the provided path is block-compressed.
|
static boolean |
isGZIPInputStream(java.io.InputStream stream)
Test whether a input stream looks like a GZIP input.
|
static boolean |
isRegularPath(java.io.File file) |
static boolean |
isRegularPath(java.nio.file.Path path) |
static boolean |
isUrl(java.lang.String input)
Returns true iff the string is a url.
|
static java.lang.String |
makeFileNameSafe(java.lang.String str)
Takes a string and replaces any characters that are not safe for filenames with an underscore
|
static SeekableStream |
maybeBufferedSeekableStream(java.io.File file) |
static SeekableStream |
maybeBufferedSeekableStream(SeekableStream stream) |
static SeekableStream |
maybeBufferedSeekableStream(SeekableStream stream,
int bufferSize) |
static SeekableStream |
maybeBufferedSeekableStream(java.net.URL url) |
static java.io.InputStream |
maybeBufferInputStream(java.io.InputStream is) |
static java.io.InputStream |
maybeBufferInputStream(java.io.InputStream is,
int bufferSize) |
static java.io.OutputStream |
maybeBufferOutputStream(java.io.OutputStream os) |
static java.io.OutputStream |
maybeBufferOutputStream(java.io.OutputStream os,
int bufferSize) |
static java.io.Reader |
maybeBufferReader(java.io.Reader reader) |
static java.io.Reader |
maybeBufferReader(java.io.Reader reader,
int bufferSize) |
static java.io.Writer |
maybeBufferWriter(java.io.Writer writer) |
static java.io.Writer |
maybeBufferWriter(java.io.Writer writer,
int bufferSize) |
static java.io.File |
newTempFile(java.lang.String prefix,
java.lang.String suffix,
java.io.File[] tmpDirs)
Creates a new tmp file on one of the potential filesystems that has at least 5GB free.
|
static java.io.File |
newTempFile(java.lang.String prefix,
java.lang.String suffix,
java.io.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 java.nio.file.Path |
newTempPath(java.lang.String prefix,
java.lang.String suffix,
java.nio.file.Path[] tmpDirs)
Creates a new tmp file on one of the potential filesystems that has at least 5GB free.
|
static java.nio.file.Path |
newTempPath(java.lang.String prefix,
java.lang.String suffix,
java.nio.file.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 java.io.BufferedReader |
openFileForBufferedReading(java.io.File file)
Checks that a file exists and is readable, and then returns a buffered reader for it.
|
static java.io.BufferedReader |
openFileForBufferedReading(java.nio.file.Path path)
Checks that a path exists and is readable, and then returns a buffered reader for it.
|
static java.io.BufferedReader |
openFileForBufferedUtf8Reading(java.io.File file)
Opens a file for reading, decompressing it if necessary
|
static java.io.BufferedWriter |
openFileForBufferedUtf8Writing(java.io.File file)
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error
|
static java.io.BufferedWriter |
openFileForBufferedUtf8Writing(java.nio.file.Path path)
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error
|
static java.io.BufferedWriter |
openFileForBufferedWriting(java.io.File file)
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error
|
static java.io.BufferedWriter |
openFileForBufferedWriting(java.io.File file,
boolean append)
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error
|
static java.io.BufferedWriter |
openFileForBufferedWriting(java.nio.file.Path path,
java.nio.file.OpenOption... openOptions)
Preferred over PrintStream and PrintWriter because an exception is thrown on I/O error
|
static java.io.OutputStream |
openFileForMd5CalculatingWriting(java.io.File file) |
static java.io.OutputStream |
openFileForMd5CalculatingWriting(java.nio.file.Path file) |
static java.io.InputStream |
openFileForReading(java.io.File file)
Opens a file for reading, decompressing it if necessary
|
static java.io.InputStream |
openFileForReading(java.nio.file.Path path)
Opens a file for reading, decompressing it if necessary
|
static java.io.OutputStream |
openFileForWriting(java.io.File file)
Opens a file for writing, overwriting the file if it already exists
|
static java.io.OutputStream |
openFileForWriting(java.io.File file,
boolean append)
Opens a file for writing, gzip it if it ends with ".gz" or "bfq"
|
static java.io.OutputStream |
openFileForWriting(java.nio.file.Path path,
java.nio.file.OpenOption... openOptions)
Opens a file for writing, gzip it if it ends with ".gz" or "bfq"
|
static java.io.InputStream |
openGzipFileForReading(java.io.File file)
Opens a GZIP-encoded file for reading, decompressing it if necessary
|
static java.io.InputStream |
openGzipFileForReading(java.nio.file.Path path)
Opens a GZIP-encoded file for reading, decompressing it if necessary
|
static java.io.OutputStream |
openGzipFileForWriting(java.io.File file,
boolean append)
Opens a GZIP encoded file for writing
|
static java.io.OutputStream |
openGzipFileForWriting(java.nio.file.Path path,
java.nio.file.OpenOption... openOptions)
Opens a GZIP encoded file for writing
|
static java.lang.String |
readFully(java.io.InputStream in)
Reads everything from an input stream as characters and returns a single String.
|
static IterableOnceIterator<java.lang.String> |
readLines(java.io.File f)
Returns an iterator over the lines in a text file.
|
static void |
recursiveDelete(java.nio.file.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(java.io.File fileOrDirectory)
Returns the size (in bytes) of the file or directory and all it's children.
|
static java.lang.String |
slurp(java.io.File file)
Convenience overload for
slurp(java.io.InputStream, java.nio.charset.Charset) using the default charset Charset.defaultCharset() . |
static java.lang.String |
slurp(java.io.InputStream is)
Convenience overload for
slurp(java.io.InputStream, java.nio.charset.Charset) using the default charset Charset.defaultCharset() . |
static java.lang.String |
slurp(java.io.InputStream is,
java.nio.charset.Charset charSet)
Reads all of the stream into a String, decoding with the provided
Charset then closes the stream quietly. |
static java.util.List<java.lang.String> |
slurpLines(java.io.File file)
Returns all of the untrimmed lines in the provided file.
|
static java.util.List<java.lang.String> |
slurpLines(java.io.InputStream is) |
static java.io.BufferedInputStream |
toBufferedStream(java.io.InputStream stream)
Wrap the given stream in a BufferedInputStream, if it isn't already wrapper
|
static java.nio.file.Path |
toPath(java.io.File fileOrNull) |
static void |
transferByStream(java.io.InputStream in,
java.io.OutputStream out,
long bytes)
Transfers from the input stream to the output stream using stream operations and a buffer.
|
static java.util.List<java.io.File> |
unrollFiles(java.util.Collection<java.io.File> inputs,
java.lang.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.
|
static java.util.List<java.nio.file.Path> |
unrollPaths(java.util.Collection<java.nio.file.Path> inputs,
java.lang.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).
|
@Deprecated public static final int STANDARD_BUFFER_SIZE
Defaults.NON_ZERO_BUFFER_SIZE
instead.public static final long ONE_GB
public static final long TWO_GBS
public static final long FIVE_GBS
@Deprecated public static final java.lang.String VCF_FILE_EXTENSION
FileExtensions.VCF
instead.@Deprecated public static final java.lang.String VCF_INDEX_EXTENSION
FileExtensions.VCF_INDEX
instead.@Deprecated public static final java.lang.String BCF_FILE_EXTENSION
FileExtensions.BCF
instead.@Deprecated public static final java.lang.String COMPRESSED_VCF_FILE_EXTENSION
FileExtensions.COMPRESSED_VCF
instead.@Deprecated public static final java.lang.String COMPRESSED_VCF_INDEX_EXTENSION
FileExtensions.COMPRESSED_VCF_INDEX
instead.@Deprecated public static final java.util.List<java.lang.String> VCF_EXTENSIONS_LIST
FileExtensions.VCF_LIST
instead.@Deprecated public static final java.lang.String[] VCF_EXTENSIONS
FileExtensions.VCF_LIST
instead.@Deprecated public static final java.lang.String INTERVAL_LIST_FILE_EXTENSION
FileExtensions.INTERVAL_LIST
instead.@Deprecated public static final java.lang.String SAM_FILE_EXTENSION
FileExtensions.SAM
instead.@Deprecated public static final java.lang.String DICT_FILE_EXTENSION
FileExtensions.DICT
instead.@Deprecated public static final java.util.Set<java.lang.String> BLOCK_COMPRESSED_EXTENSIONS
FileExtensions.BLOCK_COMPRESSED
instead.public static final int GZIP_HEADER_READ_LENGTH
isGZIPInputStream(InputStream)
public static void setCompressionLevel(int compressionLevel)
compressionLevel
- 0 <= compressionLevel <= 9public static int getCompressionLevel()
public static java.io.BufferedInputStream toBufferedStream(java.io.InputStream stream)
stream
- stream to be wrappedpublic static void transferByStream(java.io.InputStream in, java.io.OutputStream out, long bytes)
public static java.io.OutputStream maybeBufferOutputStream(java.io.OutputStream os)
public static java.io.OutputStream maybeBufferOutputStream(java.io.OutputStream os, int bufferSize)
public static SeekableStream maybeBufferedSeekableStream(SeekableStream stream, int bufferSize)
public static SeekableStream maybeBufferedSeekableStream(SeekableStream stream)
public static SeekableStream maybeBufferedSeekableStream(java.io.File file)
public static SeekableStream maybeBufferedSeekableStream(java.net.URL url)
public static java.io.InputStream maybeBufferInputStream(java.io.InputStream is)
public static java.io.InputStream maybeBufferInputStream(java.io.InputStream is, int bufferSize)
public static java.io.Reader maybeBufferReader(java.io.Reader reader, int bufferSize)
public static java.io.Reader maybeBufferReader(java.io.Reader reader)
public static java.io.Writer maybeBufferWriter(java.io.Writer writer, int bufferSize)
public static java.io.Writer maybeBufferWriter(java.io.Writer writer)
public static void deleteFiles(java.io.File... files)
files
- Files to be deleted.public static void deleteFiles(java.lang.Iterable<java.io.File> files)
public static void deletePaths(java.nio.file.Path... paths)
public static void deletePaths(java.lang.Iterable<java.nio.file.Path> paths)
paths
- an iterable of Paths to deletepublic static void deletePath(java.nio.file.Path path)
public static boolean isRegularPath(java.io.File file)
public static boolean isRegularPath(java.nio.file.Path path)
public static java.io.File newTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File[] tmpDirs, long minBytesFree) throws java.io.IOException
java.io.IOException
public static java.io.File newTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File[] tmpDirs) throws java.io.IOException
java.io.IOException
public static java.io.File getDefaultTmpDir()
public static java.nio.file.Path newTempPath(java.lang.String prefix, java.lang.String suffix, java.nio.file.Path[] tmpDirs, long minBytesFree) throws java.io.IOException
java.io.IOException
public static java.nio.file.Path newTempPath(java.lang.String prefix, java.lang.String suffix, java.nio.file.Path[] tmpDirs) throws java.io.IOException
java.io.IOException
public static java.nio.file.Path getDefaultTmpDirPath()
public static void deleteOnExit(java.nio.file.Path path)
Path
for deletion on JVM exit.DeleteOnExitPathHook
public static java.lang.String basename(java.io.File f)
public static void assertInputIsValid(java.lang.String input)
input
- the input to check for validitypublic static boolean isUrl(java.lang.String input)
public static void assertFileIsReadable(java.io.File file)
file
- the file to check for readabilitypublic static void assertFileIsReadable(java.nio.file.Path path)
path
- the file to check for readabilitypublic static void assertFilesAreReadable(java.util.List<java.io.File> files)
files
- the list of files to check for readabilitypublic static void assertPathsAreReadable(java.util.List<java.nio.file.Path> paths)
paths
- the list of paths to check for readabilitypublic static void assertInputsAreValid(java.util.List<java.lang.String> inputs)
inputs
- the list of files to check for readabilitypublic static void assertFileIsWritable(java.io.File file)
file
- the file to check for writabilitypublic static void assertFilesAreWritable(java.util.List<java.io.File> files)
files
- the list of files to check for writabilitypublic static void assertDirectoryIsWritable(java.io.File dir)
dir
- the dir to check for writabilitypublic static void assertDirectoryIsWritable(java.nio.file.Path dir)
dir
- the dir to check for writabilitypublic static void assertDirectoryIsReadable(java.io.File dir)
dir
- the dir to check for writabilitypublic static void assertFilesEqual(java.io.File f1, java.io.File f2)
public static void assertFileSizeNonZero(java.io.File file)
public static java.io.InputStream openFileForReading(java.io.File file)
file
- The file to openpublic static java.io.InputStream openFileForReading(java.nio.file.Path path)
path
- The file to openpublic static java.io.InputStream openGzipFileForReading(java.io.File file)
file
- The file to openpublic static java.io.InputStream openGzipFileForReading(java.nio.file.Path path)
path
- The file to openpublic static java.io.OutputStream openFileForWriting(java.io.File file)
file
- the file to write topublic static java.io.OutputStream openFileForWriting(java.io.File file, boolean append)
file
- the file to write toappend
- whether to append to the file if it already exists (we overwrite it if false)public static java.io.OutputStream openFileForWriting(java.nio.file.Path path, java.nio.file.OpenOption... openOptions)
path
- the file to write toopenOptions
- options to use when opening the filepublic static boolean hasGzipFileExtension(java.nio.file.Path path)
public static java.io.BufferedWriter openFileForBufferedWriting(java.io.File file, boolean append)
public static java.io.BufferedWriter openFileForBufferedWriting(java.nio.file.Path path, java.nio.file.OpenOption... openOptions)
public static java.io.BufferedWriter openFileForBufferedWriting(java.io.File file)
public static java.io.BufferedWriter openFileForBufferedUtf8Writing(java.io.File file)
public static java.io.BufferedWriter openFileForBufferedUtf8Writing(java.nio.file.Path path)
public static java.io.BufferedReader openFileForBufferedUtf8Reading(java.io.File file)
file
- The file to openpublic static java.io.OutputStream openGzipFileForWriting(java.io.File file, boolean append)
file
- the file to write toappend
- whether to append to the file if it already exists (we overwrite it if false)public static java.io.OutputStream openGzipFileForWriting(java.nio.file.Path path, java.nio.file.OpenOption... openOptions)
path
- the file to write toopenOptions
- options to control how the file is openedpublic static java.io.OutputStream openFileForMd5CalculatingWriting(java.io.File file)
public static java.io.OutputStream openFileForMd5CalculatingWriting(java.nio.file.Path file)
public static void copyStream(java.io.InputStream input, java.io.OutputStream output)
input
- contents to be copiedoutput
- destinationpublic static void copyFile(java.io.File input, java.io.File output)
public static java.io.File[] getFilesMatchingRegexp(java.io.File directory, java.lang.String regexp)
directory
- regexp
- public static java.io.File[] getFilesMatchingRegexp(java.io.File directory, java.util.regex.Pattern regexp)
public static boolean deleteDirectoryTree(java.io.File fileOrDirectory)
public static long sizeOfTree(java.io.File fileOrDirectory)
public static void copyDirectoryTree(java.io.File fileOrDirectory, java.io.File destination)
public static java.io.File createTempDir(java.lang.String prefix, java.lang.String suffix)
prefix
- The prefix string to be used in generating the file's name; must be at least three characters longsuffix
- The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be usedpublic static java.io.BufferedReader openFileForBufferedReading(java.io.File file)
public static java.io.BufferedReader openFileForBufferedReading(java.nio.file.Path path)
public static java.lang.String makeFileNameSafe(java.lang.String str)
public static java.lang.String fileSuffix(java.io.File f)
public static java.lang.String getFullCanonicalPath(java.io.File file)
public static java.lang.String readFully(java.io.InputStream in)
public static IterableOnceIterator<java.lang.String> readLines(java.io.File f)
f
- a file that is to be read in as textpublic static java.util.List<java.lang.String> slurpLines(java.io.File file) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static java.util.List<java.lang.String> slurpLines(java.io.InputStream is) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static java.lang.String slurp(java.io.File file) throws java.io.FileNotFoundException
slurp(java.io.InputStream, java.nio.charset.Charset)
using the default charset Charset.defaultCharset()
.java.io.FileNotFoundException
public static java.lang.String slurp(java.io.InputStream is)
slurp(java.io.InputStream, java.nio.charset.Charset)
using the default charset Charset.defaultCharset()
.public static java.lang.String slurp(java.io.InputStream is, java.nio.charset.Charset charSet)
Charset
then closes the stream quietly.public static java.util.List<java.io.File> unrollFiles(java.util.Collection<java.io.File> inputs, java.lang.String... extensions)
public static java.util.List<java.nio.file.Path> unrollPaths(java.util.Collection<java.nio.file.Path> inputs, java.lang.String... extensions)
public static boolean hasScheme(java.lang.String uriString)
uriString
- the URI to checktrue
if the given URI has a scheme, false
if
not, or if the URI is malformed.public static java.nio.file.Path getPath(java.lang.String uriString) throws java.io.IOException
Path
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).uriString
- the URI to convertPath
java.io.IOException
- an I/O error occurs creating the file systempublic static java.util.List<java.nio.file.Path> getPaths(java.util.List<java.lang.String> uriStrings) throws RuntimeIOException
RuntimeIOException
public static java.nio.file.Path toPath(java.io.File fileOrNull)
public static java.util.List<java.nio.file.Path> filesToPaths(java.util.Collection<java.io.File> files)
files
- a List
of File
s to convert to Path
spublic static boolean isGZIPInputStream(java.io.InputStream stream)
stream
- the input stream.java.lang.IllegalArgumentException
- if `stream` cannot mark or reset the streampublic static java.nio.file.Path addExtension(java.nio.file.Path path, java.lang.String extension)
path
- the path to start from, eg. "/folder/file.jpg"extension
- the extension to add, eg. ".bak"public static boolean isBlockCompressed(java.nio.file.Path path, boolean checkExtension) throws java.io.IOException
Note that using checkExtension=true
would avoid the cost of opening the file, but
if hasBlockCompressedExtension(String)
returns false
this would not detect
block-compressed files such BAM.
path
- file to check if it is block-compressed.checkExtension
- if true
, checks the extension before opening the file.true
if the file is block-compressed; false
otherwise.java.io.IOException
- if there is an I/O error.public static boolean isBlockCompressed(java.nio.file.Path path) throws java.io.IOException
Note that block-compressed file extensions FileExtensions.BLOCK_COMPRESSED
are not
checked by this method.
path
- file to check if it is block-compressed.true
if the file is block-compressed; false
otherwise.java.io.IOException
- if there is an I/O error.public static boolean hasBlockCompressedExtension(java.lang.String fileName)
FileExtensions.BLOCK_COMPRESSED
.fileName
- string name for the file. May be an HTTP/S url.true
if the file has a block-compressed extension; false
otherwise.public static boolean hasBlockCompressedExtension(java.nio.file.Path path)
FileExtensions.BLOCK_COMPRESSED
.path
- object to extract the name from.true
if the path has a block-compressed extension; false
otherwise.public static boolean hasBlockCompressedExtension(java.io.File file)
FileExtensions.BLOCK_COMPRESSED
.file
- object to extract the name from.true
if the file has a block-compressed extension; false
otherwise.public static boolean hasBlockCompressedExtension(java.net.URI uri)
FileExtensions.BLOCK_COMPRESSED
.uri
- file as an URI.true
if the file has a block-compressed extension; false
otherwise.public static void recursiveDelete(java.nio.file.Path directory)
directory
- The directory to be deleted (along with its subdirectories)