1 4 package org.oddjob.util; 5 6 import java.io.ByteArrayOutputStream ; 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import java.io.ObjectOutputStream ; 10 import java.io.OutputStream ; 11 import java.io.Serializable ; 12 13 16 public class IO { 17 18 19 27 public static void copy(InputStream in, OutputStream out) throws IOException { 28 byte b[] = new byte[8192]; 29 int i; 30 while ((i = in.read(b)) != -1) { 31 out.write(b, 0, i); 32 } 33 } 34 35 41 public static boolean canSerialize(Object o) { 42 if (o == null) { 43 return true; 44 } 45 if (!(o instanceof Serializable )) { 46 return false; 47 } 48 ByteArrayOutputStream os = new ByteArrayOutputStream (); 49 try { 50 ObjectOutputStream s = new ObjectOutputStream (os); 51 s.writeObject(o); 52 } catch (IOException e) { 53 return false; 54 } 55 return true; 56 } 57 58 } 59 | Popular Tags |