public static Set<Long> readSetOfLongs(DataInput in) throws IOException {
  int size=in.readInt();
  if (size < 0) {
    return null;
  }
 else {
    Set result=new HashSet(size);
    boolean longIDs=in.readBoolean();
    for (int i=0; i < size; i++) {
      long l=longIDs ? in.readLong() : in.readInt();
      result.add(Long.valueOf(l));
    }
    return result;
  }
}

public static Set < Long > readSetOfLongs ( DataInput in ) throws IOException { int size = in . readInt ( ) ; if ( size < 0 ) { return null ; } else { Set result = new HashSet ( size ) ; boolean longIDs = in . readBoolean ( ) ; for ( int i = 0 ; i < size ; i ++ ) { long l = longIDs ? in . readLong ( ) : in . readInt ( ) ; result . add ( Long . valueOf ( l ) ) ; } return result ; } }
read a set of long objects
