1 18 package org.apache.activemq.transport.util; 19 20 import java.io.DataInput ; 21 import java.io.DataInputStream ; 22 import java.io.DataOutput ; 23 import java.io.DataOutputStream ; 24 import java.io.IOException ; 25 import java.io.Reader ; 26 import org.apache.activemq.util.ByteArrayInputStream; 27 import org.apache.activemq.util.ByteArrayOutputStream; 28 import org.apache.activemq.util.ByteSequence; 29 import org.apache.activemq.wireformat.WireFormat; 30 31 36 public abstract class TextWireFormat implements WireFormat { 37 38 public abstract Object unmarshalText(String text); 39 public abstract Object unmarshalText(Reader reader); 40 public abstract String marshalText(Object command); 41 42 public void marshal(Object command, DataOutput out) throws IOException { 43 out.writeUTF(marshalText(command)); 44 } 45 46 public Object unmarshal(DataInput in) throws IOException { 47 String text = in.readUTF(); 48 return unmarshalText(text); 49 } 50 51 public ByteSequence marshal(Object command) throws IOException { 52 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 53 DataOutputStream dos = new DataOutputStream (baos); 54 marshal(command, dos); 55 dos.close(); 56 return baos.toByteSequence(); 57 } 58 59 public Object unmarshal(ByteSequence packet) throws IOException { 60 ByteArrayInputStream stream = new ByteArrayInputStream(packet); 61 DataInputStream dis = new DataInputStream (stream); 62 return unmarshal(dis); 63 } 64 65 } 66 | Popular Tags |