Class MultiSourceReader

java.lang.Object
java.io.Reader
graphql.parser.MultiSourceReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

@PublicApi public class MultiSourceReader extends Reader
This reader allows you to read N number readers and combine them as one logical reader however you can then map back to the underlying readers in terms of their source name and the relative lines numbers. It can also track all data in memory if you want to have all of the previous read data in place at some point in time.
  • Field Details

  • Constructor Details

  • Method Details

    • read

      public int read(char[] cbuf, int off, int len) throws IOException
      Specified by:
      read in class Reader
      Throws:
      IOException
    • trackData

      private void trackData(char[] cbuf, int off, int len)
    • calcLineNumber

      private int calcLineNumber()
    • getSourceAndLineFromOverallLine

      public MultiSourceReader.SourceAndLine getSourceAndLineFromOverallLine(int overallLineNumber)
      This returns the source name and line number given an overall line number This is zeroes based like LineNumberReader.getLineNumber()
      Parameters:
      overallLineNumber - the over all line number
      Returns:
      the source name and relative line number to that source
    • getLineNumber

      public int getLineNumber()
      Returns:
      the line number of the current source. This is zeroes based like LineNumberReader.getLineNumber()
    • getSourceName

      public String getSourceName()
      Returns:
      The name of the current source
    • getOverallLineNumber

      public int getOverallLineNumber()
      Returns:
      the overall line number of the all the sources. This is zeroes based like LineNumberReader.getLineNumber()
    • getData

      public List<String> getData()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Reader
      Throws:
      IOException
    • newMultiSourceReader

      public static MultiSourceReader.Builder newMultiSourceReader()