public final class IOUtils
extends java.lang.Object
Modifier and Type | Method | Description |
---|---|---|
static void |
close(java.io.Closeable... objects) |
Closes all given Closeables.
|
static void |
close(java.lang.Exception e,
java.io.Closeable... objects) |
Closes all given Closeables.
|
static void |
close(java.lang.Exception ex,
java.lang.Iterable<? extends java.io.Closeable> objects) |
Closes all given
Closeable s. |
static void |
close(java.lang.Iterable<? extends java.io.Closeable> objects) |
Closes all given Closeables.
|
static void |
closeWhileHandlingException(java.io.Closeable... objects) |
Closes all given
Closeable s, suppressing all thrown exceptions. |
static void |
closeWhileHandlingException(java.lang.Iterable<? extends java.io.Closeable> objects) |
Closes all given
Closeable s, suppressing all thrown exceptions. |
static void |
deleteFilesIgnoringExceptions(java.nio.file.Path... files) |
Deletes all given files, suppressing all thrown
IOException s. |
static void |
deleteFilesIgnoringExceptions(java.util.Collection<? extends java.nio.file.Path> files) |
Deletes all given files, suppressing all thrown
IOException s. |
static void |
fsync(java.nio.file.Path fileToSync,
boolean isDir) |
Ensure that any writes to the given file is written to the storage device that contains it.
|
static void |
rm(java.nio.file.Path... locations) |
Deletes one or more files or directories (and everything underneath it).
|
public static void close(java.io.Closeable... objects) throws java.io.IOException
objects
- objects to closejava.io.IOException
public static void close(java.lang.Exception e, java.io.Closeable... objects) throws java.io.IOException
Exception
is null. If
no exceptions are encountered and the passed in exception is null, it completes normally.objects
- objects to closejava.io.IOException
public static void close(java.lang.Iterable<? extends java.io.Closeable> objects) throws java.io.IOException
objects
- objects to closejava.io.IOException
public static void close(java.lang.Exception ex, java.lang.Iterable<? extends java.io.Closeable> objects) throws java.io.IOException
Closeable
s. If a non-null exception is passed in, or closing a
stream causes an exception, throws the exception with other RuntimeException
or
IOException
exceptions added as suppressed.ex
- existing Exception to add exceptions occurring during close toobjects
- objects to closejava.io.IOException
close(Closeable...)
public static void closeWhileHandlingException(java.io.Closeable... objects)
Closeable
s, suppressing all thrown exceptions. Some of the Closeable
s may be null, they are ignored.objects
- objects to closepublic static void closeWhileHandlingException(java.lang.Iterable<? extends java.io.Closeable> objects)
Closeable
s, suppressing all thrown exceptions.objects
- objects to closecloseWhileHandlingException(Closeable...)
public static void deleteFilesIgnoringExceptions(java.nio.file.Path... files)
IOException
s. Some of the files may be null, if so they are ignored.files
- the paths of files to deletepublic static void deleteFilesIgnoringExceptions(java.util.Collection<? extends java.nio.file.Path> files)
IOException
s. Some of the files may be null, if so they are ignored.files
- the paths of files to deletepublic static void rm(java.nio.file.Path... locations) throws java.io.IOException
java.io.IOException
- if any of the given files (or their sub-hierarchy files in case of directories) cannot be removed.public static void fsync(java.nio.file.Path fileToSync, boolean isDir) throws java.io.IOException
isDir
parameter specifies
whether or not the path to sync is a directory. This is needed because we open for read and ignore an IOException
since not
all filesystems and operating systems support fsyncing on a directory. For regular files we must open for write for the fsync to have
an effect.fileToSync
- the file to fsyncisDir
- if true, the given file is a directory (we open for read and ignore IOException
s, because not all file
systems and operating systems allow to fsync on a directory)java.io.IOException