/**
   * Writes the results of the last call to annotate() to the specified directory in HDFS. This is
   * equivalent to serializing the results of a call to annotate() to the directory.
   *
   * @param outputDir The directory to which the results of the last call to annotate() should be
   *     written. Each serialized document should be named with the document's hash.
   */
  public void writeOutputFromLastAnnotate(Path outputDir) throws TException, IOException {
    Path fileLoc = getLocForSerializedForm(lastAnnotatedRecord, outputDir);

    try {
      if (!transport.isOpen()) {
        transport.open();
      }
      serializer.serialize(lastAnnotatedRecord, fileLoc, hdfs);

      Record reconstructed = serializer.deserialize(fileLoc, hdfs);
      if (!RecordTools.hasAnnotations(reconstructed)) {
        throw new IOException(
            "Reconstructed record has no annotations, but original has the following: "
                + RecordTools.getContents(lastAnnotatedRecord));
      }
    } finally {
      if (transport.isOpen()) {
        transport.close();
      }
    }
  }