code: public static void writeFstToBinaryStream(Fst fst, ObjectOutput out) throws IOException {
      out.writeInt(CURRENT_VERSION);
      writeStringMap(fst.getInputSymbols(), out);
      writeStringMap(fst.getOutputSymbols(), out);
      out.writeBoolean(fst.isUsingStateSymbols()); // whether or not we used a state symbol table
      if (fst.isUsingStateSymbols()) {
        writeStringMap(fst.getStateSymbols(), out);
      }
      out.writeInt(fst.getStartState().getId());
  
      out.writeObject(fst.getSemiring());
      out.writeInt(fst.getStateCount());
  
      Map<State, Integer> stateMap = new IdentityHashMap<>(fst.getStateCount());
      for (int i = 0; i < fst.getStateCount(); i++) {
        State s = fst.getState(i);
        out.writeInt(s.getArcCount());
        out.writeDouble(s.getFinalWeight());
        out.writeInt(s.getId());
        stateMap.put(s, i);
      }
  
      int numStates = fst.getStateCount();
      for (int i = 0; i < numStates; i++) {
        State s = fst.getState(i);
        int numArcs = s.getArcCount();
        for (int j = 0; j < numArcs; j++) {
          Arc a = s.getArc(j);
          out.writeInt(a.getIlabel());
          out.writeInt(a.getOlabel());
          out.writeDouble(a.getWeight());
          out.writeInt(stateMap.get(a.getNextState()));
        }
      }
    }
docs: Serializes the current Fst instance to an ObjectOutput
  
  @param out the ObjectOutput. It should be already be initialized by the caller.