|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.util.io; import java.awt.Image; import java.io.*; import java.util.*; import org.openide.ErrorManager; import org.openide.util.WeakSet; // note: keep method NbObjectInputStream.resolveObject // consistent with replaceObject method /** Object output stream that could in the future be smart about saving certain objects. * Also static methods to safely write an object that could cause problems during later deserialization. */ public class NbObjectOutputStream extends ObjectOutputStream { /** Create a new object output. * @param os the underlying output stream * @throws IOException for the usual reasons */ public NbObjectOutputStream(OutputStream os) throws IOException { super (os); try { enableReplaceObject (true); } catch (SecurityException ex) { IOException ioe = new IOException (ex.toString ()); ErrorManager.getDefault().annotate (ioe, ex); throw ioe; } } /* * @param obj is an Object to be checked for replace */ public Object replaceObject (Object obj) throws IOException { if (obj instanceof Image) { return null; // [LIGHT] // additional code needed for full version } return super.replaceObject(obj); } /** Writes an object safely to the object output. * Can be read by {@link NbObjectInputStream#readSafely}. * @param oo object output to write to * @param obj the object to write * @exception SafeException if the object simply fails to be serialized * @exception IOException if something more serious fails */ public static void writeSafely (ObjectOutput oo, Object obj) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream (200); try { NbObjectOutputStream oos = new NbObjectOutputStream (bos); oos.writeObject (obj); oos.flush (); bos.close (); } catch (Exception exc) { // exception during safe of the object // encapsulate all exceptions into safe exception oo.writeInt (0); throw new SafeException (exc); } oo.writeInt (bos.size ()); oo.write (bos.toByteArray ()); } private static final String SVUID = "serialVersionUID"; // NOI18N private static final Set alreadyReported = new WeakSet(); // Set |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.