Code example for ObjectOutputStream

Methods: defaultWriteObject, writeInt, writeObject

0
    this.getMDCCopy();
 
    // This sets the throwable sting representation of the event throwable. 
    this.getThrowableStrRep();
 
    oos.defaultWriteObject();
 
    // serialize this event's level 
    writeLevel(oos);
  } 
 
  private 
  void writeLevel(ObjectOutputStream oos) throws java.io.IOException {
 
    oos.writeInt(level.toInt());
 
    Class clazz = level.getClass();
    if(clazz == Level.class) {
      oos.writeObject(null);
    } else { 
      // writing directly the Class object would be nicer, except that 
      // serialized a Class object can not be read back by JDK 
      // 1.1.x. We have to resort to this hack instead. 
      oos.writeObject(clazz.getName());
    } 
  } 
 
}