1 30 31 32 package org.hsqldb.lib; 33 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 import java.io.ObjectInputStream ; 37 import java.io.ObjectOutputStream ; 38 import java.io.OutputStream ; 39 import java.io.Serializable ; 40 41 48 public class InOutUtil { 49 50 55 public static int readLine(InputStream in, 56 OutputStream out) throws IOException { 57 58 int count = 0; 59 60 for (;;) { 61 int b = in.read(); 62 63 if (b == -1) { 64 break; 65 } 66 67 count++; 68 69 out.write(b); 70 71 if (b == '\n') { 72 break; 73 } 74 } 75 76 return count; 77 } 78 79 87 public static byte[] serialize(Serializable s) throws IOException { 88 89 HsqlByteArrayOutputStream bo = new HsqlByteArrayOutputStream(); 90 ObjectOutputStream os = new ObjectOutputStream (bo); 91 92 os.writeObject(s); 93 94 return bo.toByteArray(); 95 } 96 97 105 public static Serializable deserialize(byte[] ba) 106 throws IOException , ClassNotFoundException { 107 108 HsqlByteArrayInputStream bi = new HsqlByteArrayInputStream(ba); 109 ObjectInputStream is = new ObjectInputStream (bi); 110 111 return (Serializable ) is.readObject(); 112 } 113 } 114 | Popular Tags |