public final class XIOUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static Charset |
CHARSET_UTF_8
Deprecated.
Use
StandardCharsets instead.
|
static String |
UTF_8
UTF-8 charset string.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
close(Closeable
Closes all given
Closeables.
|
static void |
close(Iterable
Closes all given
Closeables.
|
static void |
closeWhileHandlingException(Closeable
Closes all given
Closeables, suppressing all thrown exceptions.
|
static void |
closeWhileHandlingException(Iterable
Closes all given
Closeables, suppressing all thrown exceptions.
|
static void |
deleteFilesIfExist(Collection
Deletes all given
Paths, if they exist.
|
static void |
deleteFilesIfExist(Path
Deletes all given
Paths, if they exist.
|
static void |
deleteFilesIgnoringExceptions(Collection
Deletes all given files, suppressing all thrown IOExceptions.
|
static void |
deleteFilesIgnoringExceptions(org
Deletes all given files, suppressing all thrown IOExceptions.
|
static void |
deleteFilesIgnoringExceptions(Path
Deletes all given files, suppressing all thrown IOExceptions.
|
static void |
fsync(Path
Ensure that any writes to the given file is written to the storage device that contains it.
|
static Reader |
getDecodingReader(Class
Opens a Reader for the given resource using a
CharsetDecoder.
|
static Reader |
getDecodingReader(InputStream
Wrapping the given
InputStream in a reader using a
CharsetDecoder.
|
static void |
reThrow(Throwable
Simple utility method that takes a previously caught
Throwable and rethrows either
IOException or an unchecked exception.
|
static void |
reThrowUnchecked(Throwable
Simple utility method that takes a previously caught
Throwable and rethrows it as an unchecked exception.
|
static void |
rm(Path
Deletes one or more files or directories (and everything underneath it).
|
@Deprecated public static final CharsetCHARSET_UTF_8
StandardCharsets.UTF_8 instead.
Charset instance to prevent repeated
Charset.forName(String) lookups
public static final StringUTF_8
Where possible, use StandardCharsets instead, as using the String constant may slow things down.
StandardCharsets.UTF_8
public static void close(Closeable... objects) throws IOException
objects - objects to call
close() on
IOException
public static void close(Iterable<? extends Closeable > objects) throws IOException
IOException
close(Closeable...)
public static void closeWhileHandlingException(Closeable... objects)
objects - objects to call
close() on
public static void closeWhileHandlingException(Iterable<? extends Closeable > objects)
public static ReadergetDecodingReader(InputStream stream, Charset charSet)
InputStream in a reader using a
CharsetDecoder. Unlike Java's defaults this reader will throw an exception if your it detects the read charset doesn't match the expected
Charset.
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
stream - the stream to wrap in a reader
charSet - the expected charset
public static ReadergetDecodingReader(Class <?> clazz, String resource, Charset charSet) throws IOException
CharsetDecoder. Unlike Java's defaults this reader will throw an exception if your it detects the read charset doesn't match the expected
Charset.
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
clazz - the class used to locate the resource
resource - the resource name to load
charSet - the expected charset
IOException
public static void deleteFilesIgnoringExceptions(org.apache .lucene .store .Directory dir, String ... files)
Note that the files should not be null.
public static void deleteFilesIgnoringExceptions(Path... files)
Some of the files may be null, if so they are ignored.
public static void deleteFilesIgnoringExceptions(Collection<? extends Path > files)
Some of the files may be null, if so they are ignored.
public static void deleteFilesIfExist(Path... files) throws IOException
files - files to delete
IOException
public static void deleteFilesIfExist(Collection<? extends Path > files) throws IOException
files - files to delete
IOException
public static void rm(Path... locations) throws IOException
IOException - if any of the given files (or their subhierarchy files in case of directories) cannot be removed.
public static void reThrow(Throwableth) throws IOException
Throwable and rethrows either
IOException or an unchecked exception. If the argument is null then this method does nothing.
IOException
public static void reThrowUnchecked(Throwableth)
Throwable and rethrows it as an unchecked exception. If the argument is null then this method does nothing.
public static void fsync(PathfileToSync, boolean isDir) throws IOException
fileToSync - the file to fsync
isDir - if true, the given file is a directory (we open for read and ignore IOExceptions, because not all file systems and operating systems allow to fsync on a directory)
IOException