FileDocCategorySizeDatePackage
SerializationTester.javaAPI DocJava SE 5 API1384Fri Aug 26 14:56:48 BST 2005java.awt.dnd

SerializationTester

public final class SerializationTester extends Object
Tests if an object can truly be serialized by serializing it to a null OutputStream.
version
1.5, 12/19/03
since
1.4

Fields Summary
private static ObjectOutputStream
stream
Constructors Summary
private SerializationTester()

Methods Summary
static booleantest(java.lang.Object obj)

        try {
            stream = new ObjectOutputStream(new OutputStream() {
                    public void write(int b) {}
                });
        } catch (IOException cannotHappen) {
        }
    
        if (!(obj instanceof Serializable)) {
            return false;
        }

        try {
            stream.writeObject(obj);
        } catch (IOException e) {
            return false;
        } finally {
            // Fix for 4503661. 
            // Reset the stream so that it doesn't keep a reference to the
            // written object.
            try {
                stream.reset();
            } catch (IOException e) {
                // Ignore the exception.
            }
        }
        return true;