List of utility methods to do Object Serialize and Deserialize
Object | deserialise(byte[] bytes) deserialise ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); Object object = ois.readObject(); ois.close(); return object; |
Serializable | deserialiseFromByteArray(byte b[]) You better have a good reason for using this. return ((Serializable) (new ObjectInputStream(new ByteArrayInputStream(b))).readObject()); |
T | deserializaObjeto(byte[] bytes, Class Deseriza un array de bytes en un objeto java del tipo indicado. if (bytes == null) { return null; ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(byteIn); @SuppressWarnings("unchecked") T obj = (T) in.readObject(); in.close(); ... |
T | deserialize(final String serializable, final Class deserialize try (final ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream((byte[]) Base64.getDecoder().decode(serializable)))) { return valueType.cast(in.readObject()); |
Object | deserialize(String name) deserialize try { FileInputStream fileIn = new FileInputStream(name); ObjectInputStream in = new ObjectInputStream(fileIn); Object object = in.readObject(); in.close(); fileIn.close(); return object; } catch (Exception i) { ... |
Properties | deserialize(String serialized) deserialize StringReader reader = new StringReader(serialized); Properties properties = new Properties(); properties.load(reader); reader.close(); return properties; |
Object | deserialize(String serializedObject) deserialize try { byte b[] = Base64.getDecoder().decode(serializedObject); ByteArrayInputStream bi = new ByteArrayInputStream(b); ObjectInputStream si = new ObjectInputStream(bi); return si.readObject(); } catch (Exception e) { System.out.println(e); return null; ... |
Object | deserialize(String str) deserialize if (str == null || str.length() == 0) { return null; try { ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str)); ObjectInputStream objStream = new ObjectInputStream(serialObj); return objStream.readObject(); } catch (Exception e) { ... |
Object | deSerialize(String str) de Serialize byte[] byteFromStr = str.getBytes("ISO-8859-1"); return deSerialize(byteFromStr); |
T | deserializeAndCheckObject(final byte[] object, final Class extends Serializable> type) Decode and serialize object. final Object result = deserialize(object); if (!type.isAssignableFrom(result.getClass())) { throw new ClassCastException( "Decoded object is of type " + result.getClass() + " when we were expecting " + type); return (T) result; |