Class SGFLoader


  • public class SGFLoader
    extends java.lang.Object
    A way to load SGF files. This class handles SGF File Formats 3 and 4. The API is extremely simple, so subclassing to handle different file formats shouldn't be difficult.
    • Constructor Summary

      Constructors 
      Constructor Description
      SGFLoader()
      constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SGFGame load​(java.io.InputStream is)
      Returns a new SGFGame, provided a valid (and open) InputStream.
      protected SGFToken readToken​(java.io.StreamTokenizer st)
      Reads an SGF token, provided a StreamTokenizer to help with parsing the text into SGFTokens.
      • Methods inherited from class java.lang.Object

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

      • SGFLoader

        public SGFLoader()
        constructor. Barry: I would really like this class to be abstract and this method protected, but jigo classes use it.
    • Method Detail

      • load

        public SGFGame load​(java.io.InputStream is)
                     throws java.io.IOException,
                            SGFException
        Returns a new SGFGame, provided a valid (and open) InputStream.

        Given an input stream, this method will parse its contents and return a full SGFGame, complete with board markings, comments, and variations. On some minor errors (like syntax problems with the file), the parsing will stop and return whatever was parsed to that point.

        Since everything is static, only one thread at a time may load a game.

        Parameters:
        is - - The InputStream from which contains SGF 3 or SGF 4 data.
        Returns:
        A complete SGFGame, or null on unrecoverable errors.
        Throws:
        java.io.IOException
        SGFException
      • readToken

        protected SGFToken readToken​(java.io.StreamTokenizer st)
                              throws java.io.IOException,
                                     SGFException
        Reads an SGF token, provided a StreamTokenizer to help with parsing the text into SGFTokens. In order to support importing of game types other than go, I have made this method abstract. See implementations in derived classes. (Barry 2007) Barry: I would really like this method to be Abstract, but jigo classes need to use this

        Parameters:
        st - - The StreamTokenizer from which to read an SGF token.
        Returns:
        An SGFToken representing a piece of information about the game.
        Throws:
        java.io.IOException
        SGFException