1 package org.sapia.util.license; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.ObjectInputStream ; 7 import java.io.ObjectOutputStream ; 8 import java.io.OutputStream ; 9 10 21 public class LicenseUtils { 22 23 31 public static Object fromBytes(InputStream bytes) throws IOException { 32 ObjectInputStream ois = new ObjectInputStream (bytes); 33 try{ 34 return ois.readObject(); 35 }catch(ClassNotFoundException e){ 36 throw new IOException ("Class not found - " + e.getMessage()); 37 }finally{ 38 if(ois != null) 39 ois.close(); 40 } 41 } 42 43 50 public static byte[] toBytes(Object serializable) throws IOException { 51 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 52 toBytes(serializable, bos); 53 return bos.toByteArray(); 54 } 55 56 67 public static void toBytes(Object serializable, OutputStream os) throws IOException { 68 ObjectOutputStream oos = new ObjectOutputStream (os); 69 try{ 70 oos.writeObject(serializable); 71 }finally{ 72 oos.flush(); 73 oos.close(); 74 } 75 } 76 } 77 | Popular Tags |