Class IOUtils
java.lang.Object
org.elasticsearch.core.internal.io.IOUtils
Utilities for common I/O methods. Borrowed heavily from Lucene (org.apache.lucene.util.IOUtils).
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
static void
Closes all givenCloseable
s.static void
Closes all givenCloseable
s.static void
Closes all givenCloseable
s.static void
Closes all givenCloseable
s.static void
closeWhileHandlingException
(Closeable closeable) static void
closeWhileHandlingException
(Closeable... objects) Closes all givenCloseable
s, suppressing all thrown exceptions.static void
closeWhileHandlingException
(Iterable<? extends Closeable> objects) Closes all givenCloseable
s, suppressing all thrown exceptions.static void
deleteFilesIgnoringExceptions
(Path... files) Deletes all given files, suppressing all thrownIOException
s.static void
deleteFilesIgnoringExceptions
(Collection<? extends Path> files) Deletes all given files, suppressing all thrownIOException
s.static void
Ensure that any writes to the given file is written to the storage device that contains it.static void
Ensure that any writes to the given file is written to the storage device that contains it.static void
Deletes one or more files or directories (and everything underneath it).
-
Field Details
-
UTF_8
UTF-8 charset string.Where possible, use
StandardCharsets.UTF_8
instead, as using the String constant may slow things down.- See Also:
-
WINDOWS
public static final boolean WINDOWS -
LINUX
public static final boolean LINUX -
MAC_OS_X
public static final boolean MAC_OS_X
-
-
Method Details
-
close
Closes all givenCloseable
s. Some of the Closeables may be null; they are ignored. After everything is closed, the method either throws the first exception it hit while closing with other exceptions added as suppressed, or completes normally if there were no exceptions.- Parameters:
objects
- objects to close- Throws:
IOException
-
close
- Throws:
IOException
- See Also:
-
close
Closes all givenCloseable
s. Some of the Closeables may be null; they are ignored. After everything is closed, the method adds any exceptions as suppressed to the original exception, or throws the first exception it hit ifException
is null. If no exceptions are encountered and the passed in exception is null, it completes normally.- Parameters:
objects
- objects to close- Throws:
IOException
-
close
Closes all givenCloseable
s. Some of the Closeables may be null; they are ignored. After everything is closed, the method either throws the first exception it hit while closing with other exceptions added as suppressed, or completes normally if there were no exceptions.- Parameters:
objects
- objects to close- Throws:
IOException
-
close
Closes all givenCloseable
s. If a non-null exception is passed in, or closing a stream causes an exception, throws the exception with otherRuntimeException
orIOException
exceptions added as suppressed.- Parameters:
ex
- existing Exception to add exceptions occurring during close toobjects
- objects to close- Throws:
IOException
- See Also:
-
closeWhileHandlingException
Closes all givenCloseable
s, suppressing all thrown exceptions. Some of theCloseable
s may be null, they are ignored.- Parameters:
objects
- objects to close
-
closeWhileHandlingException
Closes all givenCloseable
s, suppressing all thrown exceptions.- Parameters:
objects
- objects to close- See Also:
-
closeWhileHandlingException
-
deleteFilesIgnoringExceptions
Deletes all given files, suppressing all thrownIOException
s. Some of the files may be null, if so they are ignored.- Parameters:
files
- the paths of files to delete
-
deleteFilesIgnoringExceptions
Deletes all given files, suppressing all thrownIOException
s. Some of the files may be null, if so they are ignored.- Parameters:
files
- the paths of files to delete
-
rm
Deletes one or more files or directories (and everything underneath it).- Throws:
IOException
- if any of the given files (or their sub-hierarchy files in case of directories) cannot be removed.
-
fsync
Ensure that any writes to the given file is written to the storage device that contains it. TheisDir
parameter specifies whether or not the path to sync is a directory. This is needed because we open for read and ignore anIOException
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.- Parameters:
fileToSync
- the file to fsyncisDir
- if true, the given file is a directory (we open for read and ignoreIOException
s, because not all file systems and operating systems allow to fsync on a directory)- Throws:
IOException
-
fsync
Ensure that any writes to the given file is written to the storage device that contains it. TheisDir
parameter specifies whether or not the path to sync is a directory. This is needed because we open for read and ignore anIOException
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.- Parameters:
fileToSync
- the file to fsyncisDir
- if true, the given file is a directory (we open for read and ignoreIOException
s, because not all file systems and operating systems allow to fsync on a directory)metaData
- iftrue
both the file's content and metadata will be sync, otherwise only the file's content will be sync- Throws:
IOException
-