public final class GeometryIOUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T> void |
acceptUnchecked(IOConsumer<T> consumer,
T arg)
Pass the given argument to the consumer, wrapping any
IOException with
UncheckedIOException . |
static <T> int |
applyAsIntUnchecked(IOToIntFunction<T> fn,
T arg)
Call the given function with the argument and return the
int result, wrapping any
IOException with UncheckedIOException . |
static void |
closeUnchecked(Closeable closeable)
Close the argument, wrapping any IO exceptions with
UncheckedIOException . |
static BufferedReader |
createBufferedReader(GeometryInput input,
Charset defaultCharset)
Create a
BufferedReader for reading from the given input. |
static BufferedWriter |
createBufferedWriter(GeometryOutput output,
Charset defaultCharset)
Create a
BufferedWriter for writing to the given output. |
static <T,I extends InputStream> |
createCloseableStream(IOFunction<I,Stream<T>> streamFunction,
IOSupplier<? extends I> inputStreamSupplier)
Create a stream associated with an input stream.
|
static UncheckedIOException |
createUnchecked(IOException exc)
Create an unchecked exception from the given checked exception.
|
static String |
getFileExtension(String fileName)
Get the part of the file name after the last dot.
|
static String |
getFileName(Path path)
Get the file name of the given path or null if one does not exist
or is the empty string.
|
static String |
getFileName(String path)
Get the file name from the given path string, defined as
the substring following the last path separator character.
|
static String |
getFileName(URL url)
Get the file name of the given url or null if one does not exist or is
the empty string.
|
static <T> T |
getUnchecked(IOSupplier<T> supplier)
|
static IllegalStateException |
parseError(String msg)
Create an exception indicating a parsing or syntax error.
|
static IllegalStateException |
parseError(String msg,
Throwable cause)
Create an exception indicating a parsing or syntax error.
|
static <T,C extends Closeable> |
tryApplyCloseable(IOFunction<C,T> function,
IOSupplier<? extends C> closeableSupplier)
Pass a supplied
Closeable instance to function and return the result. |
public static String getFileName(Path path)
path
- path to get the file name ofpublic static String getFileName(URL url)
url
- url to get the file name ofpublic static String getFileName(String path)
path
- path to get the file name frompublic static String getFileExtension(String fileName)
fileName
- file name to get the extension forpublic static BufferedReader createBufferedReader(GeometryInput input, Charset defaultCharset)
BufferedReader
for reading from the given input. The charset used is the charset
defined in input
or defaultCharset
if null.input
- input to read fromdefaultCharset
- charset to use if no charset is defined in the inputUncheckedIOException
- if an I/O error occurspublic static BufferedWriter createBufferedWriter(GeometryOutput output, Charset defaultCharset)
BufferedWriter
for writing to the given output. The charset used is the charset
defined in output
or defaultCharset
if null.output
- output to write todefaultCharset
- charset to use if no charset is defined in the outputUncheckedIOException
- if an I/O error occurspublic static <T> T getUnchecked(IOSupplier<T> supplier)
T
- returned typesupplier
- object supplying the return valueUncheckedIOException
- if an I/O error occurspublic static <T> void acceptUnchecked(IOConsumer<T> consumer, T arg)
IOException
with
UncheckedIOException
.T
- argument typeconsumer
- function to callarg
- function argumentUncheckedIOException
- if an I/O error occurspublic static <T> int applyAsIntUnchecked(IOToIntFunction<T> fn, T arg)
int
result, wrapping any
IOException
with UncheckedIOException
.T
- argument typefn
- function to callarg
- function argumentUncheckedIOException
- if an I/O error occurspublic static void closeUnchecked(Closeable closeable)
UncheckedIOException
.closeable
- argument to closeUncheckedIOException
- if an I/O error occurspublic static UncheckedIOException createUnchecked(IOException exc)
exc
- exception to wrap in an unchecked exceptionpublic static IllegalStateException parseError(String msg)
msg
- exception messagepublic static IllegalStateException parseError(String msg, Throwable cause)
msg
- exception messagecause
- exception causepublic static <T,C extends Closeable> T tryApplyCloseable(IOFunction<C,T> function, IOSupplier<? extends C> closeableSupplier)
Closeable
instance to function
and return the result.
The Closeable
instance returned by the supplier is closed if function execution
fails, otherwise the instance is not closed.T
- Return typeC
- Closeable typefunction
- function called with the supplied Closeable instancecloseableSupplier
- supplier used to obtain a Closeable instancefunction
with a supplied Closeable instanceUncheckedIOException
- if an I/O error occurspublic static <T,I extends InputStream> Stream<T> createCloseableStream(IOFunction<I,Stream<T>> streamFunction, IOSupplier<? extends I> inputStreamSupplier)
IOException
thrown
when the input stream is closed after the return of this method are wrapped with UncheckedIOException
.T
- Stream element typeI
- Input stream typestreamFunction
- function accepting an input stream and returning a streaminputStreamSupplier
- supplier used to obtain the input streamUncheckedIOException
- if an I/O error occurs during input stream and stream creationCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.