Class ResourceAsLines
- java.lang.Object
-
- com.adelean.inject.resources.core.ResourceAsLines
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ResourceAsLines extends java.lang.Object implements java.lang.AutoCloseableWrapper for resource that may open that resource as stream of text lines.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidforEachLine(java.util.function.Consumer<java.lang.String> lineConsumer)ApplieslineConsumerto each text line from resource.voidforEachLineChecked(ThrowingConsumer<java.lang.String> lineConsumer)ApplieslineConsumerto each text line from resource.java.util.stream.Stream<java.lang.String>lines()Returns stream of text lines from wrapped resource.ResourceAsLinesonFirstLine(java.util.function.Consumer<java.lang.String> firstLineConsumer)Defines hook that is executed when first line of resource was read.ResourceAsLinesonFirstLineChecked(ThrowingConsumer<java.lang.String> firstLineConsumer)Defines hook that is executed when first line of resource was read.<T> java.util.stream.Stream<T>parseLines(java.util.function.Function<java.lang.String,T> parsingFunction)AppliesparsingFunctionto each text line from resource and returns the resulting stream.<T> java.util.stream.Stream<T>parseLinesChecked(ThrowingFunction<java.lang.String,T> parsingFunction)AppliesparsingFunctionto each text line from resource and returns the resulting stream.
-
-
-
Method Detail
-
onFirstLine
public ResourceAsLines onFirstLine(java.util.function.Consumer<java.lang.String> firstLineConsumer)
Defines hook that is executed when first line of resource was read. Useful for processing of headers.- Parameters:
firstLineConsumer- consumer of the first line from resource- Returns:
- this
ResourceAsLineswrapper
-
onFirstLineChecked
public ResourceAsLines onFirstLineChecked(ThrowingConsumer<java.lang.String> firstLineConsumer)
Defines hook that is executed when first line of resource was read. Hook may throw an exception Useful for processing of headers.- Parameters:
firstLineConsumer- consumer of the first line from resource. May throw an exception- Returns:
- this
ResourceAsLineswrapper
-
lines
public java.util.stream.Stream<java.lang.String> lines()
Returns stream of text lines from wrapped resource.If
firstLineConsumeris not null, the first line will be excluded from returned stream. First line will be processed byfirstLineConsumerinstead.- Returns:
- steam of text lines from resource
-
parseLines
public <T> java.util.stream.Stream<T> parseLines(java.util.function.Function<java.lang.String,T> parsingFunction)
AppliesparsingFunctionto each text line from resource and returns the resulting stream.If
firstLineConsumeris not null, the first line will be excluded from processed stream. First line will be processed byfirstLineConsumerinstead.- Type Parameters:
T- type of elements of result stream- Parameters:
parsingFunction- function that parses a single text line- Returns:
- stream of results of
parsingFunction
-
parseLinesChecked
public <T> java.util.stream.Stream<T> parseLinesChecked(ThrowingFunction<java.lang.String,T> parsingFunction)
AppliesparsingFunctionto each text line from resource and returns the resulting stream.parsingFunctionmay throw an exception.If
firstLineConsumeris not null, the first line will be excluded from processed stream. First line will be processed byfirstLineConsumerinstead.- Type Parameters:
T- type of elements of result stream- Parameters:
parsingFunction- function that parses a single text line. May throw an exception- Returns:
- stream of results of
parsingFunction
-
forEachLine
public void forEachLine(java.util.function.Consumer<java.lang.String> lineConsumer)
ApplieslineConsumerto each text line from resource.If
firstLineConsumeris not null, the first line will be excluded from processed stream. First line will be processed byfirstLineConsumerinstead.- Parameters:
lineConsumer- consumer of a single line
-
forEachLineChecked
public void forEachLineChecked(ThrowingConsumer<java.lang.String> lineConsumer)
ApplieslineConsumerto each text line from resource.lineConsumermay throw an exception.If
firstLineConsumeris not null, the first line will be excluded from processed stream. First line will be processed byfirstLineConsumerinstead.- Parameters:
lineConsumer- consumer of a single line. May throw an exception
-
close
public void close() throws java.lang.Exception- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
-