List of utility methods to do Object Serialize and Deserialize
Properties | deserializeProperties(byte[] bytes) Tries to deserialize given bytes array to Properties instance Properties properties = new Properties(); if (bytes != null) { try { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); properties.load(bais); bais.close(); } catch (IOException e) { return properties; |
Serializable | deserializeRaw(byte[] array) deserialize Raw byteInput = new ByteArrayInputStream(array); objectInput = new ObjectInputStream(byteInput); Serializable o = (Serializable) objectInput.readObject(); return o; |
void | deserializeSafe(byte[] buf, T obj) deserialize Safe ByteArrayInputStream bis = null; try { bis = new ByteArrayInputStream(buf); ObjectInputStream oin = null; try { oin = new ObjectInputStream(bis); obj.readExternal(oin); } finally { ... |
short | deserializeShort(byte[] inbuf, int offset) Deserialize a short, but do not convert it from little endian in the process return (short) ((inbuf[offset] & 0xff) << 8 | (inbuf[offset + 1] & 0xff)); |
Object | deserializeStream(final String witness) Deserializes a specified file. FileInputStream fileIs = new FileInputStream(witness); ObjectInputStream objIs = new ObjectInputStream(fileIs); return objIs.readObject(); |
Object | serializeAndDeserialize(Object o) Serializes and deserializes the given object. ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bytes); try { out.writeObject(o); } finally { out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())); ... |
Object | serializeAndDeserialize(Object o) serialize And Deserialize ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); oos.flush(); baos.flush(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(is); ... |
Object | serializeAndDeserialize(Object obj) serialize And Deserialize ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(obj); out.flush(); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(bin); obj = in.readObject(); return obj; ... |
T | serializeAndDeserialize(T input) Serialize and Deserialize an object Useful for testing if serialization is correctly handled for a class. final ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(byteArrayStream); out.writeObject(input); final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteArrayStream.toByteArray())); @SuppressWarnings("unchecked") final T result = (T) in.readObject(); out.close(); in.close(); ... |
T | serializeAndDeserialize(T instance) serialize And Deserialize return (T) deserialize(serialize(instance));
|