org.apache.wicket.core.util.objects.checker
Class CheckingObjectOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ObjectOutputStream
          extended by org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable, ObjectOutput, ObjectStreamConstants
Direct Known Subclasses:
SerializableChecker

public class CheckingObjectOutputStream
extends ObjectOutputStream

Checks an object tree during serialization for wrong state by delegating the work to the used IObjectCheckers.

As this class depends heavily on JDK's serialization internals using introspection, analyzing may not be possible, for instance when the runtime environment does not have sufficient rights to set fields accessible that would otherwise be hidden. You should call isAvailable() to see whether this class can operate properly. An ObjectOutputStream that uses IObjectCheckers to check the state of the object before serializing it. If the checker returns IObjectChecker.Result.Status.FAILURE then the serialization process is stopped and the error is logged.


Nested Class Summary
static class CheckingObjectOutputStream.ObjectCheckException
           
 
Nested classes/interfaces inherited from class java.io.ObjectOutputStream
ObjectOutputStream.PutField
 
Field Summary
 
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
 
Constructor Summary
CheckingObjectOutputStream(OutputStream outputStream, IObjectChecker... checkers)
          Constructor.
 
Method Summary
 void close()
           
static boolean isAvailable()
          Gets whether we can execute the tests.
 void reset()
           
protected  String toPrettyPrintedStack(String type)
          Dump with indentation.
protected  void writeObjectOverride(Object obj)
           
 
Methods inherited from class java.io.ObjectOutputStream
annotateClass, annotateProxyClass, defaultWriteObject, drain, enableReplaceObject, flush, putFields, replaceObject, useProtocolVersion, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeClassDescriptor, writeDouble, writeFields, writeFloat, writeInt, writeLong, writeObject, writeShort, writeStreamHeader, writeUnshared, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckingObjectOutputStream

public CheckingObjectOutputStream(OutputStream outputStream,
                                  IObjectChecker... checkers)
                           throws IOException,
                                  SecurityException
Constructor.

Parameters:
outputStream - the output stream where the serialized object will be written upon successful check
checkers - the checkers that will actually check the objects
Throws:
IOException
SecurityException
Method Detail

isAvailable

public static boolean isAvailable()
Gets whether we can execute the tests. If false, calling check(Object) will just return and you are advised to rely on the NotSerializableException. Clients are advised to call this method prior to calling the check method.

Returns:
whether security settings and underlying API etc allow for accessing the serialization API using introspection

toPrettyPrintedStack

protected final String toPrettyPrintedStack(String type)
Dump with indentation.

Parameters:
type - the type that couldn't be serialized
Returns:
A very pretty dump

writeObjectOverride

protected final void writeObjectOverride(Object obj)
                                  throws IOException
Overrides:
writeObjectOverride in class ObjectOutputStream
Throws:
IOException
See Also:
ObjectOutputStream.writeObjectOverride(java.lang.Object)

reset

public void reset()
           throws IOException
Overrides:
reset in class ObjectOutputStream
Throws:
IOException
See Also:
ObjectOutputStream.reset()

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in interface ObjectOutput
Overrides:
close in class ObjectOutputStream
Throws:
IOException


Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.