Class GeometryIOUtils
java.lang.Object
org.apache.commons.geometry.io.core.internal.GeometryIOUtils
Internal class containing utility methods for IO operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charPath separator character used on Unix-like systems.private static final charPath separator character used on Windows. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidacceptUnchecked(IOConsumer<T> consumer, T arg) Pass the given argument to the consumer, wrapping anyIOExceptionwithUncheckedIOException.static <T> intapplyAsIntUnchecked(IOToIntFunction<T> fn, T arg) Call the given function with the argument and return theintresult, wrapping anyIOExceptionwithUncheckedIOException.private static RunnablecloseAsUncheckedRunnable(Closeable closeable) Return aRunnablethat callson the argument, wrapping anyinvalid reference
close()IOExceptionwithUncheckedIOException.static voidcloseUnchecked(Closeable closeable) Close the argument, wrapping any IO exceptions withUncheckedIOException.static BufferedReadercreateBufferedReader(GeometryInput input, Charset defaultCharset) Create aBufferedReaderfor reading from the given input.static BufferedWritercreateBufferedWriter(GeometryOutput output, Charset defaultCharset) Create aBufferedWriterfor writing to the given output.static <T,I extends InputStream>
Stream<T> createCloseableStream(IOFunction<I, Stream<T>> streamFunction, IOSupplier<? extends I> inputStreamSupplier) Create a stream associated with an input stream.static UncheckedIOExceptionCreate an unchecked exception from the given checked exception.static StringgetFileExtension(String fileName) Get the part of the file name after the last dot.static StringgetFileName(String path) Get the file name from the given path string, defined as the substring following the last path separator character.static StringgetFileName(URL url) Get the file name of the given url or null if one does not exist or is the empty string.static StringgetFileName(Path path) Get the file name of the given path or null if one does not exist or is the empty string.static <T> TgetUnchecked(IOSupplier<T> supplier) static IllegalStateExceptionparseError(String msg) Create an exception indicating a parsing or syntax error.static IllegalStateExceptionparseError(String msg, Throwable cause) Create an exception indicating a parsing or syntax error.static <T,C extends Closeable>
TtryApplyCloseable(IOFunction<C, T> function, IOSupplier<? extends C> closeableSupplier) Pass a suppliedCloseableinstance tofunctionand return the result.
-
Field Details
-
UNIX_PATH_SEP
private static final char UNIX_PATH_SEPPath separator character used on Unix-like systems.- See Also:
-
WINDOWS_PATH_SEP
private static final char WINDOWS_PATH_SEPPath separator character used on Windows.- See Also:
-
-
Constructor Details
-
GeometryIOUtils
private GeometryIOUtils()Utility class; no instantiation.
-
-
Method Details
-
getFileName
Get the file name of the given path or null if one does not exist or is the empty string.- Parameters:
path- path to get the file name of- Returns:
- file name of the given path
-
getFileName
Get the file name of the given url or null if one does not exist or is the empty string.- Parameters:
url- url to get the file name of- Returns:
- file name of the given url
-
getFileName
Get the file name from the given path string, defined as the substring following the last path separator character. Null is returned if the argument is null or the file name is the empty string.- Parameters:
path- path to get the file name from- Returns:
- file name of the given path string or null if a non-empty file name does not exist
-
getFileExtension
Get the part of the file name after the last dot.- Parameters:
fileName- file name to get the extension for- Returns:
- the extension of the file name, the empty string if no extension is found, or null if the argument is null
-
createBufferedReader
Create aBufferedReaderfor reading from the given input. The charset used is the charset defined ininputordefaultCharsetif null.- Parameters:
input- input to read fromdefaultCharset- charset to use if no charset is defined in the input- Returns:
- new reader instance
- Throws:
UncheckedIOException- if an I/O error occurs
-
createBufferedWriter
Create aBufferedWriterfor writing to the given output. The charset used is the charset defined inoutputordefaultCharsetif null.- Parameters:
output- output to write todefaultCharset- charset to use if no charset is defined in the output- Returns:
- new writer instance
- Throws:
UncheckedIOException- if an I/O error occurs
-
getUnchecked
- Type Parameters:
T- returned type- Parameters:
supplier- object supplying the return value- Returns:
- supplied value
- Throws:
UncheckedIOException- if an I/O error occurs
-
acceptUnchecked
Pass the given argument to the consumer, wrapping anyIOExceptionwithUncheckedIOException.- Type Parameters:
T- argument type- Parameters:
consumer- function to callarg- function argument- Throws:
UncheckedIOException- if an I/O error occurs
-
applyAsIntUnchecked
Call the given function with the argument and return theintresult, wrapping anyIOExceptionwithUncheckedIOException.- Type Parameters:
T- argument type- Parameters:
fn- function to callarg- function argument- Returns:
- int value
- Throws:
UncheckedIOException- if an I/O error occurs
-
closeUnchecked
Close the argument, wrapping any IO exceptions withUncheckedIOException.- Parameters:
closeable- argument to close- Throws:
UncheckedIOException- if an I/O error occurs
-
createUnchecked
Create an unchecked exception from the given checked exception. The message of the returned exception contains the original exception's type and message.- Parameters:
exc- exception to wrap in an unchecked exception- Returns:
- the unchecked exception
-
parseError
Create an exception indicating a parsing or syntax error.- Parameters:
msg- exception message- Returns:
- an exception indicating a parsing or syntax error
-
parseError
Create an exception indicating a parsing or syntax error.- Parameters:
msg- exception messagecause- exception cause- Returns:
- an exception indicating a parsing or syntax error
-
tryApplyCloseable
public static <T,C extends Closeable> T tryApplyCloseable(IOFunction<C, T> function, IOSupplier<? extends C> closeableSupplier) Pass a suppliedCloseableinstance tofunctionand return the result. TheCloseableinstance returned by the supplier is closed if function execution fails, otherwise the instance is not closed.- Type Parameters:
T- Return typeC- Closeable type- Parameters:
function- function called with the supplied Closeable instancecloseableSupplier- supplier used to obtain a Closeable instance- Returns:
- result of calling
functionwith a supplied Closeable instance - Throws:
UncheckedIOException- if an I/O error occurs
-
createCloseableStream
public static <T,I extends InputStream> Stream<T> createCloseableStream(IOFunction<I, Stream<T>> streamFunction, IOSupplier<? extends I> inputStreamSupplier) Create a stream associated with an input stream. The input stream is closed when the stream is closed and also closed if stream creation fails. AnyIOExceptionthrown when the input stream is closed after the return of this method are wrapped withUncheckedIOException.- Type Parameters:
T- Stream element typeI- Input stream type- Parameters:
streamFunction- function accepting an input stream and returning a streaminputStreamSupplier- supplier used to obtain the input stream- Returns:
- stream associated with the input stream return by the supplier
- Throws:
UncheckedIOException- if an I/O error occurs during input stream and stream creation
-
closeAsUncheckedRunnable
Return aRunnablethat callson the argument, wrapping anyinvalid reference
close()IOExceptionwithUncheckedIOException.- Parameters:
closeable- instance to be closed- Returns:
- runnable that calls
invalid @code
{@code close()) on the argument
-