code: public void serialize(final Writer writer) throws IOException {
  
      for (final String type : this.headRules.keySet()) {
        final HeadRule headRule = this.headRules.get(type);
        // write num of tags
        writer.write(Integer.toString(headRule.getTags().length + 2));
        writer.write(' ');
        // write type
        writer.write(type);
        writer.write(' ');
        // write l2r true == 1
        if (headRule.isLeftToRight()) {
          writer.write("1");
        } else {
          writer.write("0");
        }
        // write tags
        for (final String tag : headRule.getTags()) {
          writer.write(' ');
          writer.write(tag);
        }
        writer.write('\n');
      }
      writer.flush();
    }
docs: Writes the head rules to the writer in a format suitable for loading the
  head rules again with the constructor. The encoding must be taken into
  account while working with the writer and reader.
  <p>
  After the entries have been written, the writer is flushed. The writer
  remains open after this method returns.
  
  @param writer
  the writer
  @throws IOException
  if io exception