public static < T extends FSA > T read ( InputStream stream , Class < ? extends T > clazz ) throws IOException { FSA fsa = read ( stream ) ; if ( ! clazz . isInstance ( fsa ) ) { throw new IOException ( String . format ( Locale . ROOT , "Expected FSA type %s, but read an incompatible type %s." , clazz . getName ( ) , fsa . getClass ( ) . getName ( ) ) ) ; } return clazz . cast ( fsa ) ; }
A factory for reading a specific FSA subclass including proper casting .