public static boolean write(Writer writer,Object toSerialize) throws Exception {
  Class<?> xstreamClass;
  java.lang.reflect.Constructor<?> constructor;
  Object xstream;
  Class<?>[] serializeArgsClasses=new Class[2];
  Object[] serializeArgs=new Object[2];
  java.lang.reflect.Method methodSerialize;
  boolean result=false;
  xstreamClass=Class.forName("com.thoughtworks.xstream.XStream");
  constructor=xstreamClass.getConstructor();
  xstream=constructor.newInstance();
  serializeArgsClasses[0]=Object.class;
  serializeArgsClasses[1]=Writer.class;
  serializeArgs[0]=toSerialize;
  serializeArgs[1]=writer;
  methodSerialize=xstreamClass.getMethod("toXML",serializeArgsClasses);
  try {
    methodSerialize.invoke(xstream,serializeArgs);
    result=true;
  }
 catch (  Exception ex) {
    result=false;
  }
  return result;
}

public static boolean write ( Writer writer , Object toSerialize ) throws Exception { Class < ? > xstreamClass ; java . lang . reflect . Constructor < ? > constructor ; Object xstream ; Class < ? > [ ] serializeArgsClasses = new Class [ 2 ] ; Object [ ] serializeArgs = new Object [ 2 ] ; java . lang . reflect . Method methodSerialize ; boolean result = false ; xstreamClass = Class . forName ( "com.thoughtworks.xstream.XStream" ) ; constructor = xstreamClass . getConstructor ( ) ; xstream = constructor . newInstance ( ) ; serializeArgsClasses [ 0 ] = Object . class ; serializeArgsClasses [ 1 ] = Writer . class ; serializeArgs [ 0 ] = toSerialize ; serializeArgs [ 1 ] = writer ; methodSerialize = xstreamClass . getMethod ( "toXML" , serializeArgsClasses ) ; try { methodSerialize . invoke ( xstream , serializeArgs ) ; result = true ; } catch ( Exception ex ) { result = false ; } return result ; }
writes the xml - serialized object to the given writer .
