Interface Source
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A source of bytes, opened on demand into a channel to read from.
Describes where bytes come from, deferring the open until read time so a re-openable
source (such as a file(Path)) may be consumed more than once.
- Since:
- 0.4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Sourcebytes(byte[] bytes) An in-memory array of bytes.static Sourcechannel(ReadableByteChannel channel) An already-open channel, passed through unchanged.static SourcedirectFile(Path path) A file, read with direct IO where the operating system and file system support it, bypassing the page cache.static SourceA file, read through the operating system's page cache.open()Open a channel over the bytes, positioned at the first.static Sourcestream(InputStream stream) An input stream, adapted to a channel.
-
Method Details
-
open
Open a channel over the bytes, positioned at the first.- Returns:
- a channel over the source's bytes
- Throws:
IOException- if the source cannot be opened
-
file
-
directFile
-
stream
An input stream, adapted to a channel. The stream is consumed once.- Parameters:
stream- the stream to read from- Returns:
- a single-use source over the stream
-
channel
An already-open channel, passed through unchanged. The channel is consumed once.- Parameters:
channel- the channel to read from- Returns:
- a single-use source over the channel
-
bytes
An in-memory array of bytes.- Parameters:
bytes- the bytes to read- Returns:
- a re-openable source over the bytes
-