List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.cj.restspecs.mojo.Util.java
public static void writeObject(Object o, File path) { try {/* w w w .j a v a 2s . co m*/ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path)); try { out.writeObject(o); } finally { out.close(); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:jedi.util.serialization.Pickle.java
/** * Serializes a object on the main memory and returns a sequence of bytes as a String. * //from ww w. jav a 2 s .c om * @param o Object to be serialized. * @return String */ public static String dumps(Object o) { String s = ""; try { // Serializing. // Reference to a sequence of bytes on the memory. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); oos.close(); // Converts a array of bytes into a String. // The default conversion doesn't works on the other hand Base64 works fine. s = new String(Base64.encodeBase64(baos.toByteArray())); baos.close(); } catch (IOException e) { e.printStackTrace(); } return s; }
From source file:RedisCache.java
/** Write the object to a Base64 string. */ private static String toString(Serializable o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);/*from ww w. ja v a2s .c o m*/ oos.close(); return new String(Base64.encodeBase64(baos.toByteArray())); }
From source file:com.ebay.erl.mobius.util.SerializableUtil.java
public final static String serializeToBase64(Serializable obj) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try {//from w ww.j av a 2 s .c om oos = new ObjectOutputStream(bos); oos.writeObject(obj); oos.flush(); oos.close(); String result = new String(Base64.encodeBase64(bos.toByteArray()), "UTF-8"); return result; } catch (NotSerializableException e) { throw new IllegalArgumentException("Cannot serialize " + obj.getClass().getCanonicalName(), e); } finally { try { bos.close(); } catch (Throwable e) { e = null; } try { if (oos != null) oos.close(); } catch (Throwable e) { e = null; } } }
From source file:org.pgptool.gui.config.impl.ConfigRepositoryImpl.java
public static void safeClose(ObjectOutputStream fis) { if (fis != null) { try {/*w w w . j av a 2s.c o m*/ fis.close(); } catch (Throwable t) { // don't care } } }
From source file:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseEncoderUtil.java
public static byte[] toBytes(String[] strings) { try {/*from w ww. j a va 2 s . c o m*/ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(strings); objectOutputStream.flush(); objectOutputStream.close(); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { NeoLogger.error("Unable to convert ''{0}'' to byte[]", Arrays.toString(strings)); } return null; }
From source file:com.jaspersoft.jasperserver.core.util.StreamUtil.java
public static byte[] compress(Object object) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); ObjectOutputStream oos = new ObjectOutputStream(gzos); oos.writeObject(object);/*from w w w . j av a 2 s .c om*/ oos.flush(); oos.close(); return baos.toByteArray(); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.StorageImpl.java
private static void save() { try {//from ww w .jav a 2 s. co m final File file = new File(System.getProperty("user.home"), "htmlunit.storage"); final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file)); out.writeObject(SINGLETON_); out.close(); } catch (final IOException e) { LOG.info("Could not save storage", e); } }
From source file:Main.java
public static boolean saveObject(Context context, Object data, String filename) { FileOutputStream out;//from w w w. j a va 2 s . c om ObjectOutputStream oout; try { out = context.openFileOutput(filename + ".odb", Context.MODE_PRIVATE); oout = new ObjectOutputStream(out); oout.writeObject(data); oout.flush(); out.flush(); oout.close(); out.close(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
/** * Serialize a java Object into a byte array * // w w w.j a va 2 s .c om * @param objToSerialize - Java Object to be serialized * @return a byte array serialized from the java Object * @throws IngestionException */ public static byte[] serializeObjToBinArr(Object objToSerialize) throws IngestionException { ByteArrayOutputStream binOut = new ByteArrayOutputStream(); try { ObjectOutputStream out = new ObjectOutputStream(binOut); out.writeObject(objToSerialize); out.close(); binOut.close(); } catch (IOException e) { throw new IngestionException(e); } return binOut.toByteArray(); }