public static void writeSetOfLongs(Set set,boolean hasLongIDs,DataOutput out) throws IOException {
  if (set == null) {
    out.writeInt(-1);
  }
 else {
    out.writeInt(set.size());
    out.writeBoolean(hasLongIDs);
    for (Iterator it=set.iterator(); it.hasNext(); ) {
      Long l=(Long)it.next();
      if (hasLongIDs) {
        out.writeLong(l.longValue());
      }
 else {
        out.writeInt((int)l.longValue());
      }
    }
  }
}

public static void writeSetOfLongs ( Set set , boolean hasLongIDs , DataOutput out ) throws IOException { if ( set == null ) { out . writeInt ( - 1 ) ; } else { out . writeInt ( set . size ( ) ) ; out . writeBoolean ( hasLongIDs ) ; for ( Iterator it = set . iterator ( ) ; it . hasNext ( ) ; ) { Long l = ( Long ) it . next ( ) ; if ( hasLongIDs ) { out . writeLong ( l . longValue ( ) ) ; } else { out . writeInt ( ( int ) l . longValue ( ) ) ; } } } }
write a set of long objects
