/** Reads an object from the given object input. * The object had to be saved by the {@link NbObjectOutputStream#writeSafely} method. * * @param oi object input * @return the read object * @exception IOException if IO error occured * @exception SafeException if the operation failed but the stream is ok * for further reading */ public static Object readSafely(ObjectInput oi) throws IOException { int size = oi.readInt(); byte[] byteArray = new byte[size]; oi.readFully(byteArray, 0, size); try { ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); NbObjectInputStream ois = new NbObjectInputStream(bis); Object obj = ois.readObject(); bis.close(); return obj; } catch (Exception exc) { // encapsulate all exceptions into safe exception throw new SafeException(exc); } catch (LinkageError le) { throw new SafeException(new InvocationTargetException(le)); } }
/** 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()); }
/** Reads an object from the given object input. * The object had to be saved by the {@link NbObjectOutputStream#writeSafely} method. * * @param oi object input * @return the read object * @exception IOException if IO error occured * @exception SafeException if the operation failed but the stream is ok * for further reading */ public static Object readSafely (ObjectInput oi) throws IOException { int size = oi.readInt (); byte[] byteArray = new byte [size]; oi.readFully (byteArray, 0, size); try { ByteArrayInputStream bis = new ByteArrayInputStream (byteArray); NbObjectInputStream ois = new NbObjectInputStream (bis); Object obj = ois.readObject (); bis.close (); return obj; } catch (Exception exc) { // encapsulate all exceptions into safe exception throw new SafeException (exc); } catch (LinkageError le) { throw new SafeException (new InvocationTargetException (le)); } }
/** Reads an object from the given object input. * The object had to be saved by the {@link NbObjectOutputStream#writeSafely} method. * * @param oi object input * @return the read object * @exception IOException if IO error occured * @exception SafeException if the operation failed but the stream is ok * for further reading */ public static Object readSafely(ObjectInput oi) throws IOException { int size = oi.readInt(); byte[] byteArray = new byte[size]; oi.readFully(byteArray, 0, size); try { ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); NbObjectInputStream ois = new NbObjectInputStream(bis); Object obj = ois.readObject(); bis.close(); return obj; } catch (Exception exc) { // encapsulate all exceptions into safe exception throw new SafeException(exc); } catch (LinkageError le) { throw new SafeException(new InvocationTargetException(le)); } }
/** Reads an object from the given object input. * The object had to be saved by the {@link NbObjectOutputStream#writeSafely} method. * * @param oi object input * @return the read object * @exception IOException if IO error occured * @exception SafeException if the operation failed but the stream is ok * for further reading */ public static Object readSafely (ObjectInput oi) throws IOException { int size = oi.readInt (); byte[] byteArray = new byte [size]; oi.readFully (byteArray, 0, size); try { ByteArrayInputStream bis = new ByteArrayInputStream (byteArray); NbObjectInputStream ois = new NbObjectInputStream (bis); Object obj = ois.readObject (); bis.close (); return obj; } catch (Exception exc) { // encapsulate all exceptions into safe exception throw new SafeException (exc); } catch (LinkageError le) { throw new SafeException (new InvocationTargetException (le)); } }
/** 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()); }
/** Reads an object from the given object input. * The object had to be saved by the {@link NbObjectOutputStream#writeSafely} method. * * @param oi object input * @return the read object * @exception IOException if IO error occured * @exception SafeException if the operation failed but the stream is ok * for further reading */ public static Object readSafely(ObjectInput oi) throws IOException { int size = oi.readInt(); byte[] byteArray = new byte[size]; oi.readFully(byteArray, 0, size); try { ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); NbObjectInputStream ois = new NbObjectInputStream(bis); Object obj = ois.readObject(); bis.close(); return obj; } catch (Exception exc) { // encapsulate all exceptions into safe exception throw new SafeException(exc); } catch (LinkageError le) { throw new SafeException(new InvocationTargetException(le)); } }
/** 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 ()); }
/** 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 ()); }
/** 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()); }
/** Reads the manager. * Deserialization may throw {@link SafeException} in case * the manager cannot be loaded correctly but the stream is still uncorrupted. */ public void readExternal (ObjectInput oi) throws IOException, ClassNotFoundException { super.readExternal (oi); Object anObj = oi.readObject (); if (anObj instanceof ExplorerManager) { manager = (ExplorerManager)anObj; panels.put (manager, new java.lang.ref.WeakReference (this)); initActionMap (null); initListening(); return; } NbMarshalledObject obj = (NbMarshalledObject) anObj; // --- read all data from main stream, it is OK now --- try { manager = (ExplorerManager) obj.get (); panels.put (manager, new java.lang.ref.WeakReference (this)); initActionMap (null); initListening(); } catch (SafeException se) { throw se; } catch (IOException ioe) { throw new SafeException (ioe); } }
/** Reads the manager. * Deserialization may throw {@link SafeException} in case * the manager cannot be loaded correctly but the stream is still uncorrupted. */ public void readExternal (ObjectInput oi) throws IOException, ClassNotFoundException { super.readExternal (oi); Object anObj = oi.readObject (); if (anObj instanceof ExplorerManager) { manager = (ExplorerManager)anObj; panels.put (manager, new java.lang.ref.WeakReference (this)); initActionMap (null); initListening(); return; } NbMarshalledObject obj = (NbMarshalledObject) anObj; // --- read all data from main stream, it is OK now --- try { manager = (ExplorerManager) obj.get (); panels.put (manager, new java.lang.ref.WeakReference (this)); initActionMap (null); initListening(); } catch (SafeException se) { throw se; } catch (IOException ioe) { throw new SafeException (ioe); } }
throw new SafeException(new IOException("Could not restore Explorer window; the root node \"" + rootName + "\" is not persistent; override Node.getHandle to fix")); // NOI18N } else { String[] exploredCtx = (String[]) fields.get ("explored", null); // NOI18N restoreSelection(root, exploredCtx, Arrays.asList(selPaths)); } catch (IOException ioe) { SafeException safe = new SafeException(ioe); if (! Utilities.compareObjects (ioe.getMessage (), ioe.getLocalizedMessage ())) { ErrorManager.getDefault().annotate(safe,
throw new SafeException(new IOException("Could not restore Explorer window; the root node \"" + rootName + "\" is not persistent; override Node.getHandle to fix")); // NOI18N } else { String[] exploredCtx = (String[]) fields.get ("explored", null); // NOI18N restoreSelection(root, exploredCtx, Arrays.asList(selPaths)); } catch (IOException ioe) { SafeException safe = new SafeException(ioe); if (! Utilities.compareObjects (ioe.getMessage (), ioe.getLocalizedMessage ())) { ErrorManager.getDefault().annotate(safe,
throw new SafeException( new IOException( "Could not restore Explorer window; the root node \"" + rootName + SafeException safe = new SafeException(ioe);
SafeException se = new SafeException (main);