code: 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);
    }
docs: A factory for reading a specific FSA subclass, including proper casting.
  
  @param stream
  The input stream to read automaton data from. The stream is not
  closed.
  @param clazz A subclass of {@link FSA} to cast the read automaton to.
  @param <T> A subclass of {@link FSA} to cast the read automaton to.
  @return Returns an instantiated automaton. Never null.
  @throws IOException
  If the input stream does not represent an automaton, is otherwise
  invalid or the class of the automaton read from the input stream
  is not assignable to <code>clazz</code>.