public static void writeTreeSet(TreeSet<?> set, DataOutput out) throws IOException {
    InternalDataSerializer.checkOut(out);

    int size;

    if (set == null) {
      size = -1;
    } else {
      size = set.size();
    }
    InternalDataSerializer.writeArrayLength(size, out);
    if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) {
      logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing TreeSet with {} elements: {}", size, set);
    }
    if (size >= 0) {
      writeObject(set.comparator(), out);
      for (Object e : set) {
        writeObject(e, out);
      }
    }
  }
Writes a <code>TreeSet</code> to a <code>DataOutput</code>. Note that even though
<code>set</code> may be an instance of a subclass of <code>TreeSet</code>,
<code>readTreeSet</code> will always return an instance of <code>TreeSet</code>, <B>not</B> an
instance of the subclass. To preserve the class type of <code>set</code>,
{@link #writeObject(Object, DataOutput)} should be used for data serialization.
<p>
If the set has a comparator then it must also be serializable.

@param set the <code>TreeSet</code> to write
@param out the {@link DataInput} to write to

@throws IOException A problem occurs while writing to <code>out</code>

@see #readTreeSet
geode-core/src/main/java/org/apache/geode/DataSerializer.java