List of utility methods to do Object Serialize and Deserialize
T | serializeAndDeserialize(T obj) serialize And Deserialize ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (ObjectOutputStream out = new ObjectOutputStream(buf)) { out.writeObject(obj); try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) { return (T) in.readObject(); |
T | serializeAndDeserialize(T object) serialize And Deserialize ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); ObjectOutputStream ostream = new ObjectOutputStream(byteOutputStream); ostream.writeObject(object); ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteOutputStream.toByteArray()); ObjectInputStream istream = new ObjectInputStream(byteInputStream); return (T) istream.readObject(); |
T | serializeAndDeserialize(T object) serialize And Deserialize byte[] array = serialize(object); return deserialize(array); |
T | serializeAndDeserialize(T object) serialize And Deserialize byte[] bytes = serialize(object); return (T) deserialize(bytes); |
void | serializeAndDeserializeObject(Object myObject) serialize And Deserialize Object try { deserialzeObject(serializeObject(myObject)); } catch (IOException e) { System.out.println("Exception: " + e.toString()); |
Object | serializeAndGetObject(Object obj) serialize And Get Object return getObjectFromByteArray(getByteObject(obj));
|
Object | serializeAndReadObject(File envHome, Object object) serialize And Read Object File output = new File(envHome, "configure.out"); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(output)); out.writeObject(object); out.close(); if (!output.exists()) { throw new IllegalStateException("Can't create the output for serialized object."); ObjectInputStream in = new ObjectInputStream(new FileInputStream(output)); ... |
Object | serializeAndRecover(Object o) Serializes an object to a bytes array and then recovers the object from the bytes array. try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bos); so.writeObject(o); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream si = new ObjectInputStream(bis); return si.readObject(); } catch (Exception e) { ... |
Object | serializeAndRecover(Object o) serialize And Recover Object result = null; File tmp = null; try { tmp = File.createTempFile("test", ".ser"); FileOutputStream fo = new FileOutputStream(tmp); ObjectOutputStream so = new ObjectOutputStream(fo); so.writeObject(o); so.flush(); ... |
T | serializeAndReturnDeserializedObject(T object) serialize And Return Deserialized Object ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(object); out.close(); ByteArrayInputStream bain = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bain); @SuppressWarnings({ "unchecked" }) T managerRead = (T) in.readObject(); ... |