List of usage examples for org.apache.commons.io.input ClassLoaderObjectInputStream close
public void close() throws IOException
From source file:com.dev.pygmy.util.Utils.java
/** * Loads a saved game from the device's memory * @return saved match if found, else returns null *///from www. j a v a 2 s . c om public static PygmyGame loadGameHistory(String path) { File file = new File(path); PygmyGame game = null; if (file.exists()) { try { ClassLoaderObjectInputStream ois = new ClassLoaderObjectInputStream(PygmyLoader.getClassLoader(), new FileInputStream(file)); game = (PygmyGame) ois.readObject(); ois.close(); } catch (Exception e) { e.printStackTrace(); } } return game; }
From source file:backtype.storm.utils.Utils.java
/** * Deserialized with ClassLoader//from w w w . jav a 2 s . c om * * @param serialized * @param loader * @return */ public static Object javaDeserializeWithCL(byte[] serialized, URLClassLoader loader) { try { ByteArrayInputStream bis = new ByteArrayInputStream(serialized); Object ret = null; if (loader != null) { ClassLoaderObjectInputStream cis = new ClassLoaderObjectInputStream(loader, bis); ret = cis.readObject(); cis.close(); } else { ObjectInputStream ois = new ObjectInputStream(bis); ret = ois.readObject(); ois.close(); } return ret; } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:gov.nasa.ensemble.common.CommonUtils.java
/** * Copy an object via Externalizable. Copying a set of interconnected objects this way will maintain all the connections. This method will also properly copy and connect loops. * // w w w .ja va2 s . c o m * @param object * @return not supplied */ public static <T extends Externalizable> T copy(T object) { ClassLoaderObjectInputStream objectInputStream = null; try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); byte[] byteArray = byteArrayOutputStream.toByteArray(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); objectInputStream = new ClassLoaderObjectInputStream(object.getClass().getClassLoader(), byteArrayInputStream); // ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); @SuppressWarnings("unchecked") T copy = (T) objectInputStream.readObject(); return copy; } catch (IOException e) { Logger.getLogger(CommonUtils.class).error("copy failed", e); } catch (ClassNotFoundException e) { Logger.getLogger(CommonUtils.class).error("copy failed", e); } finally { if (objectInputStream != null) { try { objectInputStream.close(); } catch (IOException e) { LogUtil.error(e); } } } return null; }
From source file:org.mule.transport.tcp.protocols.CustomClassLoadingLengthProtocol.java
@Override public Object read(InputStream is) throws IOException { byte[] bytes = (byte[]) super.read(is); if (bytes == null) { return null; } else {//ww w . j a va2s . c o m ClassLoaderObjectInputStream classLoaderIS = new ClassLoaderObjectInputStream(this.getClassLoader(), is); try { return classLoaderIS.readObject(); } catch (ClassNotFoundException e) { logger.warn(e.getMessage()); IOException iox = new IOException(); iox.initCause(e); throw iox; } finally { classLoaderIS.close(); } } }