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.

@FunctionalInterface public interface Source

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 Type
    Method
    Description
    static Source
    bytes(byte[] bytes)
    An in-memory array of bytes.
    static Source
    An already-open channel, passed through unchanged.
    static Source
    A file, read with direct IO where the operating system and file system support it, bypassing the page cache.
    static Source
    file(Path path)
    A file, read through the operating system's page cache.
    Open a channel over the bytes, positioned at the first.
    static Source
    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

      static Source file(Path path)
      A file, read through the operating system's page cache.
      Parameters:
      path - the path of the file to read
      Returns:
      a re-openable source over the file
    • directFile

      static Source directFile(Path path)
      A file, read with direct IO where the operating system and file system support it, bypassing the page cache.
      Parameters:
      path - the path of the file to read
      Returns:
      a re-openable source over the file
    • stream

      static Source stream(InputStream 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

      static Source channel(ReadableByteChannel 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

      static Source bytes(byte[] bytes)
      An in-memory array of bytes.
      Parameters:
      bytes - the bytes to read
      Returns:
      a re-openable source over the bytes