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
A
JacksonProvider built around an InputStream-providing bifunction and an
ObjectCodec-providing bifunction.- Author:
- Laird Nelson
-
Constructor Summary
ConstructorsConstructorDescriptionInputStreamJacksonProvider(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 voidprotected static final InputStreaminputStream(ClassLoader cl, String resourceName) Returns an openInputStreamloaded using the suppliedClassLoaderand a name of a classpath resource.protected final ObjectCodecobjectCodec(Loader<?> requestingLoader, Path<? extends Type> absolutePath) Invokes theBiFunction.apply(Object, Object)method of theobjectCodecFunctionsupplied at construction time and returns the result.protected TreeNodeMethods inherited from class org.microbean.loader.jackson.JacksonProvider
absent, get, get, list, map, names, nil, qualifiers, reader, sizeMethods inherited from class org.microbean.loader.spi.AbstractTreeBasedProvider
container, find, path, path, qualifiersMethods 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 thisInputStreamJacksonProviderimplementation; may benullmapperSupplier- aSupplier, deterministic or not, ofObjectMapperinstances; ordinarily callers should supply aSupplierthat caches; may benullresourceName- 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.dirsystem 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 thisInputStreamJacksonProviderimplementation; may benullobjectCodecFunction- aBiFunctionthat returns anObjectCodecwhen supplied with aLoaderand aPath; may benullinputStreamFunction- aBiFunctionthat returns an openInputStreamwhen supplied with aLoaderand aPath; may benullinputStreamReadConsumer- aConsumerthat is called with anInputStreamafter theInputStreamhas 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 theobjectCodecFunctionsupplied at construction time and returns the result.- Specified by:
objectCodecin classJacksonProvider- Parameters:
requestingLoader- theLoaderrequesting a value; must not benullabsolutePath- the absolutePaththerequestingLoaderis currently requesting; must not benull- Returns:
- an
ObjectCodecsuitable for the supplied arguments, ornullif thisInputStreamJacksonProvidershould not handle the current request - Idempotency:
- This method is idempotent and deterministic if the
objectCodecFunctionsupplied at construction time is. - Nullability:
- This method may return
null. - Thread Safety:
- This method is safe for concurrent use by multiple
threads, but the
objectCodecFunctionsupplied at construction time may not be.
-
rootNode
- Specified by:
rootNodein classAbstractTreeBasedProvider<TreeNode>
-
inputStream
Returns an openInputStreamloaded using the suppliedClassLoaderand a name of a classpath resource.This method never returns
null.- Parameters:
cl- theClassLoaderthat will actually cause theInputStreamto be created and opened; may benullin which case the system classloader will be used insteadresourceName- the name of the classpath resource for which anInputStreamwill be created and opened; must not benull- Returns:
- a non-
null, openInputStream - Throws:
NullPointerException- ifresourceNameisnull- 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 benullin which case no action will be taken- Throws:
UncheckedIOException- if anIOExceptionis thrown by theInputStream.close()method
-