use of java.io.ObjectOutputStream in project facebook-android-sdk by facebook.
the class AppEventStore method saveEventsToDisk.
// Only call from singleThreadExecutor
private static void saveEventsToDisk(PersistedEvents eventsToPersist) {
ObjectOutputStream oos = null;
Context context = FacebookSdk.getApplicationContext();
try {
oos = new ObjectOutputStream(new BufferedOutputStream(context.openFileOutput(PERSISTED_EVENTS_FILENAME, 0)));
oos.writeObject(eventsToPersist);
} catch (Exception e) {
Log.w(TAG, "Got unexpected exception while persisting events: ", e);
try {
context.getFileStreamPath(PERSISTED_EVENTS_FILENAME).delete();
} catch (Exception innerException) {
// ignore
}
} finally {
Utility.closeQuietly(oos);
}
}
use of java.io.ObjectOutputStream in project gephi by gephi.
the class GenericPropertyEditor method getAsText.
@Override
public String getAsText() {
if (val != null) {
ByteArrayOutputStream bos = null;
ObjectOutputStream oos = null;
try {
bos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bos);
oos.writeObject(val);
} catch (Exception e) {
e.printStackTrace();
;
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException ex) {
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException ex) {
}
}
}
if (bos != null) {
return Base64.encodeBase64String(bos.toByteArray());
}
}
return "null";
}
use of java.io.ObjectOutputStream in project facebook-android-sdk by facebook.
the class TestUtils method serializeAndUnserialize.
public static <T extends Serializable> T serializeAndUnserialize(final T t) {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
new ObjectOutputStream(os).writeObject(t);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
@SuppressWarnings("unchecked") T ret = (T) (new ObjectInputStream(is)).readObject();
return ret;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of java.io.ObjectOutputStream in project gitblit by gitblit.
the class DeepCopier method checksum.
/**
* Utility method to calculate the checksum of an object.
* @param sourceObject The object from which to establish the checksum.
* @return The checksum
* @throws IOException
*/
public static BigInteger checksum(Object sourceObject) {
if (sourceObject == null) {
return BigInteger.ZERO;
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(sourceObject);
oos.close();
MessageDigest m = MessageDigest.getInstance("SHA-1");
m.update(baos.toByteArray());
return new BigInteger(1, m.digest());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
// impossible
}
return BigInteger.ZERO;
}
use of java.io.ObjectOutputStream in project gitblit by gitblit.
the class DeepCopier method copy.
/**
* Produce a deep copy of the given object. Serializes the entire object to
* a byte array in memory. Recommended for relatively small objects.
*/
@SuppressWarnings("unchecked")
public static <T> T copy(T original) {
T o = null;
try {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(byteOut);
oos.writeObject(original);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream ois = new ObjectInputStream(byteIn);
try {
o = (T) ois.readObject();
} catch (ClassNotFoundException cex) {
// actually can not happen in this instance
}
} catch (IOException iox) {
// doesn't seem likely to happen as these streams are in memory
throw new RuntimeException(iox);
}
return o;
}
Aggregations