H
- Geometric boundary typeB
- Boundary source typeR
- Read handler typeW
- Write handler typepublic class BoundaryIOManager<H extends HyperplaneConvexSubset<?>,B extends BoundarySource<H>,R extends BoundaryReadHandler<H,B>,W extends BoundaryWriteHandler<H,B>> extends Object
read handlers
and write handlers
.
Exceptions
Despite having functionality related to I/O operations, this class has been designed to not
throw checked exceptions, in particular IOException
. The primary reasons for
this choice are
UncheckedIOException
).IOException
thrown internally by this or related classes
is wrapped with UncheckedIOException
. Other common runtime exceptions
include IllegalArgumentException
, which typically indicates mathematically invalid data, and
IllegalStateException
, which typically indicates format or parsing errors. See the method-level
documentation for more details.
Implementation note: Instances of this class are thread-safe as long as the registered handler instances are thread-safe.
Constructor and Description |
---|
BoundaryIOManager() |
Modifier and Type | Method and Description |
---|---|
Stream<H> |
boundaries(GeometryInput in,
GeometryFormat fmt,
Precision.DoubleEquivalence precision)
Return a
Stream providing access to all boundaries from the given input. |
List<GeometryFormat> |
getReadFormats()
Get the list of formats supported by the currently registered
read handlers . |
R |
getReadHandlerForFileExtension(String fileExt)
Get the
read handler for the given file extension
or null if no such handler has been registered. |
R |
getReadHandlerForFormat(GeometryFormat fmt)
Get the
read handler for the given format or
null if no such handler has been registered. |
List<R> |
getReadHandlers()
Get all registered
read handlers . |
List<GeometryFormat> |
getWriteFormats()
Get the list of formats supported by the currently registered
write handlers . |
W |
getWriteHandlerForFileExtension(String fileExt)
Get the
write handler for the given file extension
or null if no such handler has been registered. |
W |
getWriteHandlerForFormat(GeometryFormat fmt)
Get the
write handler for the given format or
null if no such handler has been registered. |
List<W> |
getWriteHandlers()
Get all registered
write handlers . |
B |
read(GeometryInput in,
GeometryFormat fmt,
Precision.DoubleEquivalence precision)
Return a
BoundarySource containing all boundaries from the given input. |
void |
registerReadHandler(R handler)
Register a
read handler with the instance, replacing
any handler previously registered for the argument's supported data format, as returned
by BoundaryReadHandler.getFormat() . |
void |
registerWriteHandler(W handler)
Register a
write handler with the instance, replacing
any handler previously registered for the argument's supported data format, as returned
by BoundaryWriteHandler.getFormat() . |
protected R |
requireReadHandler(GeometryInput in,
GeometryFormat fmt)
Get the
read handler matching the arguments, throwing an exception
on failure. |
protected W |
requireWriteHandler(GeometryOutput out,
GeometryFormat fmt)
Get the
write handler matching the arguments, throwing an exception
on failure. |
void |
unregisterReadHandler(R handler)
Unregister a previously registered
read handler ;
does nothing if the argument is null or is not currently registered. |
void |
unregisterWriteHandler(W handler)
Unregister a previously registered
write handler ;
does nothing if the argument is null or is not currently registered. |
void |
write(B src,
GeometryOutput out,
GeometryFormat fmt)
Write all boundaries from
src to the given output. |
public BoundaryIOManager()
public void registerReadHandler(R handler)
read handler
with the instance, replacing
any handler previously registered for the argument's supported data format, as returned
by BoundaryReadHandler.getFormat()
.handler
- handler to registerNullPointerException
- if handler
, its format
,
or the format's name
are nullpublic void unregisterReadHandler(R handler)
read handler
;
does nothing if the argument is null or is not currently registered.handler
- handler to unregister; may be nullpublic List<R> getReadHandlers()
read handlers
.public List<GeometryFormat> getReadFormats()
read handlers
.BoundaryReadHandler.getFormat()
public R getReadHandlerForFormat(GeometryFormat fmt)
read handler
for the given format or
null if no such handler has been registered.fmt
- format to obtain a handler forpublic R getReadHandlerForFileExtension(String fileExt)
read handler
for the given file extension
or null if no such handler has been registered. File extension comparisons are
not case-sensitive.fileExt
- file extension to obtain a handler forGeometryFormat.getFileExtensions()
public void registerWriteHandler(W handler)
write handler
with the instance, replacing
any handler previously registered for the argument's supported data format, as returned
by BoundaryWriteHandler.getFormat()
.handler
- handler to registerNullPointerException
- if handler
, its format
,
or the format's name
are nullpublic void unregisterWriteHandler(W handler)
write handler
;
does nothing if the argument is null or is not currently registered.handler
- handler to unregister; may be nullpublic List<W> getWriteHandlers()
write handlers
.public List<GeometryFormat> getWriteFormats()
write handlers
.BoundaryWriteHandler.getFormat()
public W getWriteHandlerForFormat(GeometryFormat fmt)
write handler
for the given format or
null if no such handler has been registered.fmt
- format to obtain a handler forpublic W getWriteHandlerForFileExtension(String fileExt)
write handler
for the given file extension
or null if no such handler has been registered. File extension comparisons are
not case-sensitive.fileExt
- file extension to obtain a handler forGeometryFormat.getFileExtensions()
public B read(GeometryInput in, GeometryFormat fmt, Precision.DoubleEquivalence precision)
BoundarySource
containing all boundaries from the given input.
A runtime exception may be thrown if mathematically invalid boundaries are encountered.in
- input to read boundaries fromfmt
- format of the input; if null, the format is determined implicitly from the
file extension of the input file name
precision
- precision context used for floating point comparisonsIllegalArgumentException
- if mathematically invalid data is encountered or no
read handler
can be found for the input formatIllegalStateException
- if a data format error occursUncheckedIOException
- if an I/O error occurspublic Stream<H> boundaries(GeometryInput in, GeometryFormat fmt, Precision.DoubleEquivalence precision)
Stream
providing access to all boundaries from the given input. The underlying input
stream is closed when the returned stream is closed. Callers should therefore use the returned stream
in a try-with-resources statement to ensure that all resources are properly released. Ex:
try (Stream<H> stream = manager.boundaries(in, fmt, precision)) { // access stream content }
The following exceptions may be thrown during stream iteration:
IllegalArgumentException
if mathematically invalid data is encounteredIllegalStateException
if a data format error occursUncheckedIOException
if an I/O error occursin
- input to read boundaries fromfmt
- format of the input; if null, the format is determined implicitly from the
file extension of the input file name
precision
- precision context used for floating point comparisonsIllegalArgumentException
- if no read handler
can be found for
the input formatIllegalStateException
- if a data format error occurs during stream creationUncheckedIOException
- if an I/O error occurs during stream creationpublic void write(B src, GeometryOutput out, GeometryFormat fmt)
src
to the given output.src
- object containing boundaries to writeout
- output to write boundaries tofmt
- format of the output; if null, the format is determined implicitly from the
file extension of the output GeometryIOMetadata.getFileName()
IllegalArgumentException
- if no write handler
can be found
for the output formatUncheckedIOException
- if an I/O error occursprotected R requireReadHandler(GeometryInput in, GeometryFormat fmt)
read handler
matching the arguments, throwing an exception
on failure. If fmt
is given, the handler registered for that format is returned and the
input
object is not examined. If fmt
is null, the file extension of the input
file name
is used to implicitly determine the format and locate
the handler.in
- input objectfmt
- format; may be nullfmt
or, if fmt
is null, the read handler for the
file extension indicated by the inputNullPointerException
- if in
is nullIllegalArgumentException
- if no matching handler can be foundprotected W requireWriteHandler(GeometryOutput out, GeometryFormat fmt)
write handler
matching the arguments, throwing an exception
on failure. If fmt
is given, the handler registered for that format is returned and the
input
object is not examined. If fmt
is null, the file extension of the output
file name
is used to implicitly determine the format and locate
the handler.out
- output objectfmt
- format; may be nullfmt
or, if fmt
is null, the write handler for the
file extension indicated by the outputNullPointerException
- if out
is nullIllegalArgumentException
- if no matching handler can be foundCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.