List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java
public static void putExchangeRates(Activity activity, Set<CurrencyEntity> rates) { SharedPreferences prefs = activity.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.remove(BRConstants.EXCHANGE_RATES); ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutput; try {/*from w w w . j a va 2 s .c o m*/ objectOutput = new ObjectOutputStream(arrayOutputStream); objectOutput.writeObject(rates); byte[] data = arrayOutputStream.toByteArray(); objectOutput.close(); arrayOutputStream.close(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Base64OutputStream b64 = new Base64OutputStream(out, Base64.NO_WRAP); b64.write(data); b64.close(); out.close(); editor.putString(BRConstants.EXCHANGE_RATES, new String(out.toByteArray())); editor.apply(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.alpharogroup.io.SerializedObjectExtensions.java
/** * The Method toByteArray() serialize an Object to byte array. * * @param <T>/*w ww. jav a2 s .c om*/ * the generic type of the given object * @param object * The Object to convert into a byte array. * @return The byte array from the Object. * @throws IOException * Signals that an I/O exception has occurred. */ public static <T> byte[] toByteArray(final T object) throws IOException { ByteArrayOutputStream byteArrayOutputStream = null; ObjectOutputStream objectOutputStream = null; try { byteArrayOutputStream = new ByteArrayOutputStream(FileConstants.KILOBYTE); byteArrayOutputStream.reset(); objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); objectOutputStream.close(); return byteArrayOutputStream.toByteArray(); } finally { StreamExtensions.closeOutputStream(byteArrayOutputStream); StreamExtensions.closeOutputStream(objectOutputStream); } }
From source file:de.alpharogroup.io.SerializedObjectUtils.java
/** * The Method toByteArray() serialize an Object to byte array. * * @param <T>// www .j a v a 2 s . c o m * the generic type of the given object * @param object * The Object to convert into a byte array. * @return The byte array from the Object. * @throws IOException * Signals that an I/O exception has occurred. */ public static <T> byte[] toByteArray(final T object) throws IOException { ByteArrayOutputStream byteArrayOutputStream = null; ObjectOutputStream objectOutputStream = null; try { byteArrayOutputStream = new ByteArrayOutputStream(FileConstants.KILOBYTE); byteArrayOutputStream.reset(); objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); objectOutputStream.close(); return byteArrayOutputStream.toByteArray(); } finally { StreamUtils.closeOutputStream(byteArrayOutputStream); StreamUtils.closeOutputStream(objectOutputStream); } }
From source file:at.ac.tuwien.dsg.comot.m.common.Utils.java
public static Object deepCopy(Object oldObj) throws IOException, ClassNotFoundException { ObjectOutputStream oos = null; ObjectInputStream ois = null; try {//w w w .j a v a2 s . c om ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(oldObj); oos.flush(); ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); return ois.readObject(); } finally { if (oos != null) oos.close(); if (ois != null) ois.close(); } }
From source file:com.stromberglabs.jopensurf.Surf.java
public static void saveToFile(Surf surf, String file) { try {/*from w w w. j a v a2s . c o m*/ ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(file)); stream.writeObject(surf); stream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.feilong.commons.core.lang.ObjectUtil.java
/** * ?./*from w w w .j a v a2s . com*/ * * @param serializable * the object * @return the int * @throws IOException * Signals that an I/O exception has occurred. * @see ByteArrayOutputStream#size() * @since 1.0.7 */ //XXX ?check,? public static int size(Object serializable) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(serializable); objectOutputStream.close(); return byteArrayOutputStream.size(); }
From source file:com.newatlanta.appengine.datastore.CachingDatastoreService.java
private static byte[] serialize(Object object) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream(bytesOut)); objectOut.writeObject(object);//from w w w .j a va 2s. c o m objectOut.close(); if (isDevelopment()) { // workaround for issue #2097 return encodeBase64(bytesOut.toByteArray()); } return bytesOut.toByteArray(); }
From source file:com.newatlanta.appengine.taskqueue.Deferred.java
/** * Serialize an object into a byte array. * * @param obj An object to be serialized. * @return A byte array containing the serialized object * @throws QueueFailureException If an I/O error occurs during the * serialization process./*from w w w . java 2 s. co m*/ */ private static byte[] serialize(Object obj) { try { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream(bytesOut)); objectOut.writeObject(obj); objectOut.close(); // if ( isDevelopment() ) { // workaround for issue #2097 return encodeBase64(bytesOut.toByteArray()); // } // return bytesOut.toByteArray(); } catch (IOException e) { throw new QueueFailureException(e); } }
From source file:com.gwtquickstarter.server.Deferred.java
/** * Serialize an object into a byte array. * * @param obj An object to be serialized. * @return A byte array containing the serialized object * @throws QueueFailureException If an I/O error occurs during the * serialization process./* w ww . j av a 2s . c om*/ */ private static byte[] serialize(Object obj) { try { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream(bytesOut)); objectOut.writeObject(obj); objectOut.close(); if (isDevelopment()) { // workaround for issue #2097 return encodeBase64(bytesOut.toByteArray()); } return bytesOut.toByteArray(); } catch (IOException e) { throw new QueueFailureException(e); } }
From source file:com.nineash.hutsync.client.NetworkUtilities.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 w w w . j a va 2 s .c o m oos.close(); return new String(Base64Coder.encode(baos.toByteArray())); }