List of utility methods to do Object Serialize and Deserialize
T | serializeAndUnserialize(T t) serialize And Unserialize 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) { ... |
void | serializeDeserialize(final Serializable object) serialize Deserialize final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1000); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); objectOutputStream.close(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Object deserialized = objectInputStream.readObject(); objectInputStream.close(); ... |
Object | serializeDeserialize(Object object) Serializes and deserializes an object. ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(byteOutput)); out.writeObject(object); out.flush(); byte[] outputBytes = byteOutput.toByteArray(); ObjectInputStream in = new ObjectInputStream( new BufferedInputStream(new ByteArrayInputStream(outputBytes))); return in.readObject(); ... |
T | serializeDeserialize(T obj) Tests if something is serializable. ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); final byte[] data = baos.toByteArray(); ByteArrayInputStream baip = new ByteArrayInputStream(data); ObjectInputStream ois = new ObjectInputStream(baip); return (T) ois.readObject(); ... |
T | serializeThenDeserialize(T object) serialize Then Deserialize return deserialize((Class<T>) object.getClass(), serialize(object));
|