Interface TextInput

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
FileInput, ReaderInput

@CyclicDependency(reason="factory methods") public interface TextInput extends AutoCloseable
Realizes access to external text sources. In nearly all use cases, external texts are either given by a pair (File × encoding), or as a pair (Reader × sourceInfo). SourceInfo stands for a human readable document identifier, used in error messages etc. These pairs belong together *unavoidably* when processing the text input. This class gives both situations a unified facade.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Close the stream, if there is any.
    default @Opt String
    Deliver a human readable text for the source identification.
    Deliver the stream of decoded characters.
    static TextInput
    of(File file, Charset encoding)
    Factory method.
    static TextInput
    of(Reader reader)
    Factory method.
    static TextInput
    of(Reader reader, @Opt String readableSourceInfo)
    Factory method.
  • Method Details

    • of

      static TextInput of(File file, Charset encoding)
      Factory method. The encoding is given explicitly. The name of the file will serve as the source information.
      Parameters:
      file - to read from
      encoding - the encoding in which to read from the file
      Returns:
      an instance which combines the file with the encoding
    • of

      static TextInput of(Reader reader, @Opt @Opt String readableSourceInfo)
      Factory method. The source information is given explicitly.
      Parameters:
      reader - to read from
      readableSourceInfo - the info about this source as used in error messages, etc.
      Returns:
      an instance which combines the reader with the source info
    • of

      static TextInput of(Reader reader)
      Factory method. The source information is missing.
      Parameters:
      reader - to read from
      Returns:
      an instance which combines the reader with the source info
    • getReader

      Reader getReader()
      Deliver the stream of decoded characters.
      Returns:
      the stream of decoded characters.
    • close

      default void close() throws IOException
      Close the stream, if there is any.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • getInfo

      @Opt default @Opt String getInfo()
      Deliver a human readable text for the source identification.
      Returns:
      a human readable text for the source identification.