io
Serialize arbitrary objects
public static byte[] serializeObject(Serializable object) throws Exception { ByteArrayOutputStream baos = null; ObjectOutputStream oos = null; byte[] res = null; try { baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(object); oos.flush(); res = baos.toByteArray(); } catch (Exception ex) { throw ex; } finally { try { if(oos != null) oos.close(); } catch (Exception e) { e.printStackTrace(); } } return res; }public static Serializable deserializeObject(byte[] rowObject) throws Exception { ObjectInputStream ois = null; Serializable res = null; try { ois = new ObjectInputStream(new ByteArrayInputStream(rowObject)); res = (Serializable) ois.readObject(); } catch (Exception ex) { throw ex; } finally { try { if(ois != null) ois.close(); } catch (Exception e) { e.printStackTrace(); } } return res; }Related Article:
Do you want to know how to develop your skillset to become aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to theTerms andPrivacy Policy

Thank you!
We will contact you soon.
Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor atJava Code Geeks.




