Module org.microbean.loader.jackson
Package org.microbean.loader.jackson
Class InputStreamJacksonProvider
java.lang.Object
org.microbean.loader.spi.AbstractProvider
org.microbean.loader.spi.AbstractTreeBasedProvider<TreeNode>
org.microbean.loader.jackson.JacksonProvider
org.microbean.loader.jackson.InputStreamJacksonProvider
- All Implemented Interfaces:
Provider
- Direct Known Subclasses:
JsonProvider
,PropertiesProvider
,TomlProvider
,YamlProvider
A
JacksonProvider
built around an InputStream
-providing bifunction and an
ObjectCodec
-providing bifunction.- Author:
- Laird Nelson
-
Constructor Summary
ConstructorDescriptionInputStreamJacksonProvider
(Type lowerBound, BiFunction<? super Loader<?>, ? super Path<? extends Type>, ? extends ObjectCodec> objectCodecFunction, BiFunction<? super Loader<?>, ? super Path<? extends Type>, ? extends InputStream> inputStreamFunction, Consumer<? super InputStream> inputStreamReadConsumer) Creates a newInputStreamJacksonProvider
.InputStreamJacksonProvider
(Type lowerBound, Supplier<? extends ObjectMapper> mapperSupplier, String resourceName) Creates a newInputStreamJacksonProvider
. -
Method Summary
Modifier and TypeMethodDescriptionprotected static final void
protected static final InputStream
inputStream
(ClassLoader cl, String resourceName) Returns an openInputStream
loaded using the suppliedClassLoader
and a name of a classpath resource.protected final ObjectCodec
objectCodec
(Loader<?> requestingLoader, Path<? extends Type> absolutePath) Invokes theBiFunction.apply(Object, Object)
method of theobjectCodecFunction
supplied at construction time and returns the result.protected TreeNode
Methods inherited from class org.microbean.loader.jackson.JacksonProvider
absent, get, get, list, map, names, nil, qualifiers, reader, size
Methods inherited from class org.microbean.loader.spi.AbstractTreeBasedProvider
container, find, path, path, qualifiers
Methods inherited from class org.microbean.loader.spi.AbstractProvider
get, lowerBound
-
Constructor Details
-
InputStreamJacksonProvider
public InputStreamJacksonProvider(Type lowerBound, Supplier<? extends ObjectMapper> mapperSupplier, String resourceName) Creates a newInputStreamJacksonProvider
.- Parameters:
lowerBound
- the lower type bound of thisInputStreamJacksonProvider
implementation; may benull
mapperSupplier
- aSupplier
, deterministic or not, ofObjectMapper
instances; ordinarily callers should supply aSupplier
that caches; may benull
resourceName
- a resource name that is treated first as a classpath resource and finally as the name of a file relative to the directory identified by theuser.dir
system property- See Also:
-
InputStreamJacksonProvider
public InputStreamJacksonProvider(Type lowerBound, BiFunction<? super Loader<?>, ? super Path<? extends Type>, ? extends ObjectCodec> objectCodecFunction, BiFunction<? super Loader<?>, ? super Path<? extends Type>, ? extends InputStream> inputStreamFunction, Consumer<? super InputStream> inputStreamReadConsumer) Creates a newInputStreamJacksonProvider
.- Parameters:
lowerBound
- the lower type bound of thisInputStreamJacksonProvider
implementation; may benull
objectCodecFunction
- aBiFunction
that returns anObjectCodec
when supplied with aLoader
and aPath
; may benull
inputStreamFunction
- aBiFunction
that returns an openInputStream
when supplied with aLoader
and aPath
; may benull
inputStreamReadConsumer
- aConsumer
that is called with anInputStream
after theInputStream
has been fully read; may benull
; normally should close theInputStream
-
-
Method Details
-
objectCodec
protected final ObjectCodec objectCodec(Loader<?> requestingLoader, Path<? extends Type> absolutePath) Invokes theBiFunction.apply(Object, Object)
method of theobjectCodecFunction
supplied at construction time and returns the result.- Specified by:
objectCodec
in classJacksonProvider
- Parameters:
requestingLoader
- theLoader
requesting a value; must not benull
absolutePath
- the absolutePath
therequestingLoader
is currently requesting; must not benull
- Returns:
- an
ObjectCodec
suitable for the supplied arguments, ornull
if thisInputStreamJacksonProvider
should not handle the current request - Idempotency:
- This method is idempotent and deterministic if the
objectCodecFunction
supplied at construction time is. - Nullability:
- This method may return
null
. - Thread Safety:
- This method is safe for concurrent use by multiple
threads, but the
objectCodecFunction
supplied at construction time may not be.
-
rootNode
Description copied from class:AbstractTreeBasedProvider
Returns the root node of the tree that is suitable for the suppliedLoader
andPath
, ornull
if no tree is suitable.- Specified by:
rootNode
in classAbstractTreeBasedProvider<TreeNode>
- Parameters:
requestingLoader
- theLoader
currently executing a request; must not benull
absolutePath
- the path being requested; must not benull
and must be absolute- Returns:
- the root node, or
null
-
inputStream
Returns an openInputStream
loaded using the suppliedClassLoader
and a name of a classpath resource.This method never returns
null
.- Parameters:
cl
- theClassLoader
that will actually cause theInputStream
to be created and opened; may benull
in which case the system classloader will be used insteadresourceName
- the name of the classpath resource for which anInputStream
will be created and opened; must not benull
- Returns:
- a non-
null
, openInputStream
- Throws:
NullPointerException
- ifresourceName
isnull
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null
. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
closeInputStream
- Parameters:
is
- theInputStream
; may benull
in which case no action will be taken- Throws:
UncheckedIOException
- if anIOException
is thrown by theInputStream.close()
method
-