private static void purgeUnserializable(Collection<?> objects){
  logger.trace("purgeUnserializable","starts");
  ObjectOutputStream oos=null;
  int i=0;
  for (Iterator<?> it=objects.iterator(); it.hasNext(); i++) {
    Object v=it.next();
    if (v == null || v instanceof String) {
      if (logger.traceOn()) {
        logger.trace("purgeUnserializable","Value trivially serializable: " + v);
      }
      continue;
    }
    try {
      if (oos == null)       oos=new ObjectOutputStream(new SinkOutputStream());
      oos.writeObject(v);
      if (logger.traceOn()) {
        logger.trace("purgeUnserializable","Value serializable: " + v);
      }
    }
 catch (    IOException e) {
      if (logger.traceOn()) {
        logger.trace("purgeUnserializable","Value not serializable: " + v + ": "+ e);
      }
      it.remove();
      oos=null;
    }
  }
}

private static void purgeUnserializable ( Collection < ? > objects ) { logger . trace ( "purgeUnserializable" , "starts" ) ; ObjectOutputStream oos = null ; int i = 0 ; for ( Iterator < ? > it = objects . iterator ( ) ; it . hasNext ( ) ; i ++ ) { Object v = it . next ( ) ; if ( v == null || v instanceof String ) { if ( logger . traceOn ( ) ) { logger . trace ( "purgeUnserializable" , "Value trivially serializable: " + v ) ; } continue ; } try { if ( oos == null ) oos = new ObjectOutputStream ( new SinkOutputStream ( ) ) ; oos . writeObject ( v ) ; if ( logger . traceOn ( ) ) { logger . trace ( "purgeUnserializable" , "Value serializable: " + v ) ; } } catch ( IOException e ) { if ( logger . traceOn ( ) ) { logger . trace ( "purgeUnserializable" , "Value not serializable: " + v + ": " + e ) ; } it . remove ( ) ; oos = null ; } } }
remove from the given collection any element that is not a serializable object .
