Class ColumnFileReader

java.lang.Object
net.fabricmc.mappingio.format.ColumnFileReader
All Implemented Interfaces:
Closeable, AutoCloseable

@Internal public final class ColumnFileReader extends Object implements Closeable
Reader for column-based files.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ColumnFileReader(Reader reader, char indentationChar, char columnSeparator)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    Discard the last mark.
    int
     
    boolean
     
    boolean
     
    boolean
     
    boolean
    Whether EOL has been encountered in the current line yet.
    int
    Marks the present position in the stream.
    @Nullable String
    Read and consume a column without unescaping.
    @Nullable String
    nextCol(boolean unescape)
    Read and consume a column, and unescape it if requested.
    boolean
    nextCol(String expected)
    Try to read the current column with specific expected content.
    @Nullable String
    nextCols(boolean unescape)
    Read and consume all columns until EOL, and unescape if requested.
    int
    Read and consume a column and convert it to integer.
    boolean
    nextLine(int indent)
    Read and consume until the start of the next line is reached, and return whether the following indent characters match indentationChar.
    @Nullable String
    peekCol(boolean unescape)
    Read a column without consuming, and unescape if requested.
    @Nullable String
    peekCols(boolean unescape)
    Read all columns until EOL without consuming, and unescape if requested.
    int
    Reset to last mark.
    void
    reset(int indexToResetTo)
    Reset to the mark with the specified index.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ColumnFileReader

      public ColumnFileReader(Reader reader, char indentationChar, char columnSeparator)
  • Method Details

    • close

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

      public boolean nextCol(String expected) throws IOException
      Try to read the current column with specific expected content.

      The reader will point to the next column or end of line if successful, otherwise remains unchanged.

      Parameters:
      expected - Content to expect.
      Returns:
      true if the column was read and had the expected content, false otherwise.
      Throws:
      IOException
    • nextCol

      @Nullable public @Nullable String nextCol() throws IOException
      Read and consume a column without unescaping.
      Returns:
      null if nothing has been read (first char was EOL), otherwise the read string (may be empty).
      Throws:
      IOException
    • nextCol

      @Nullable public @Nullable String nextCol(boolean unescape) throws IOException
      Read and consume a column, and unescape it if requested.
      Returns:
      null if nothing has been read (first char was EOL), otherwise the read string (may be empty).
      Throws:
      IOException
    • peekCol

      @Nullable public @Nullable String peekCol(boolean unescape) throws IOException
      Read a column without consuming, and unescape if requested. Since it doesn't consume, it won't (un)mark BOF, EOL or EOF.
      Returns:
      null if nothing has been read (first char was EOL), otherwise the read string (may be empty).
      Throws:
      IOException
    • nextCols

      @Nullable public @Nullable String nextCols(boolean unescape) throws IOException
      Read and consume all columns until EOL, and unescape if requested.
      Returns:
      null if nothing has been read (first char was EOL), otherwise the read string (may be empty).
      Throws:
      IOException
    • peekCols

      @Nullable public @Nullable String peekCols(boolean unescape) throws IOException
      Read all columns until EOL without consuming, and unescape if requested. Since it doesn't consume, it won't (un)mark BOF, EOL or EOF.
      Returns:
      null if nothing has been read (first char was EOL), otherwise the read string (may be empty).
      Throws:
      IOException
    • nextIntCol

      public int nextIntCol() throws IOException
      Read and consume a column and convert it to integer.
      Returns:
      -1 if nothing has been read (first char was EOL), otherwise the number present.
      Throws:
      IOException
    • nextLine

      public boolean nextLine(int indent) throws IOException
      Read and consume until the start of the next line is reached, and return whether the following indent characters match indentationChar.

      Empty lines are skipped if indent is 0.

      Parameters:
      indent - The number of characters to check for indentation.
      Returns:
      true if the next line has the specified indentation or higher, false otherwise.
      Throws:
      IOException
    • hasExtraIndents

      public boolean hasExtraIndents() throws IOException
      Throws:
      IOException
    • getLineNumber

      public int getLineNumber()
    • isAtEol

      public boolean isAtEol()
      Whether EOL has been encountered in the current line yet.
    • isAtBof

      public boolean isAtBof()
    • isAtEof

      public boolean isAtEof()
    • mark

      public int mark()
      Marks the present position in the stream. Subsequent calls to reset() will reposition the stream to this point. In comparison to Reader.mark(int) this method stacks, so don't forget to call discardMark() if you don't need the mark anymore.
      Returns:
      the mark index (starting at 1)
    • discardMark

      public void discardMark()
      Discard the last mark.
    • reset

      public int reset()
      Reset to last mark. The marked data isn't discarded, so can be called multiple times. If you want to reset to an older mark, use reset(int).
      Returns:
      The index of the mark that was reset to.
    • reset

      public void reset(int indexToResetTo)
      Reset to the mark with the specified index. Unless reset to 0, the marked data isn't discarded afterwards, so can be called multiple times. Use negative indices to reset to a mark relative to the current one.