Class StandardTextfileStreamTokenizer

java.lang.Object
java.io.StreamTokenizer
megamek.common.util.fileUtils.StandardTextfileStreamTokenizer

public final class StandardTextfileStreamTokenizer extends StreamTokenizer
This is a specialized StreamTokenizer that uses a configuration that many of MM's text files share. This configuration uses # for comments, double quotes for strings and information is processed line-wise. This class adds some methods to simplify line parsing.
  • Field Details

  • Constructor Details

    • StandardTextfileStreamTokenizer

      public StandardTextfileStreamTokenizer(Reader r)
      Creates a StreamTokenizer for the given Reader.
      Parameters:
      r - The Reader to tokenize such as a FileReader
    • StandardTextfileStreamTokenizer

      public StandardTextfileStreamTokenizer(InputStream is)
      Creates a StreamTokenizer for the given InputStream.
      Parameters:
      is - The InputStream to tokenize
  • Method Details

    • isValidIncludeLine

      public static boolean isValidIncludeLine(List<String> lineTokens)
      Returns true when the line given as its tokens is a valid line giving an include file. The tokens should be obtained from getLineTokens(). A valid include line has exactly two tokens, the first being "include" and the second a filename.
      Parameters:
      lineTokens - The tokens representing an input stream line
      Returns:
      True when the tokens represent a valid include statement
      See Also:
    • getLineTokens

      public List<String> getLineTokens() throws IOException
      Returns a list of tokens making up the next available input stream line. Empty lines are skipped, i.e. the tokens list will normally not be empty. It may be empty when the end of the input stream is reached. Use isFinished() to test if the stream is at its end.
      Returns:
      The tokens of the next available line that is not empty
      Throws:
      IOException
      See Also:
    • isFinished

      public boolean isFinished()
      Returns:
      True when the end of the input stream is reached. When this method returns true, the tokens list returned by getLineTokens() is empty. The finished state is updated in getLineTokens().