use of com.palantir.util.ByteArrayIOStream in project atlasdb by palantir.
the class SerializingUtils method copy.
@SuppressWarnings("unchecked")
public static <T> T copy(T orig, ObjectInputStreamFactory factory) {
T obj = null;
ObjectOutputStream out = null;
ObjectInputStream in = null;
try {
// Write the object out to a byte array
ByteArrayIOStream byteStream = new ByteArrayIOStream();
out = new ObjectOutputStream(byteStream);
out.writeObject(orig);
out.close();
// Make an input stream from the byte array and read
// a copy of the object back in.
in = factory.create(byteStream.getInputStream(), null);
obj = (T) in.readObject();
} catch (IOException e) {
log.error("IO exception", e);
} catch (ClassNotFoundException cnfe) {
log.error("class not found exception", cnfe);
} finally {
closeQuietly(in);
closeQuietly(out);
}
return obj;
}
Aggregations