Home » activemq-parent-5.3.1-source-release » org.apache » activemq » transport » util » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.transport.util;
   18   
   19   import java.io.DataInput;
   20   import java.io.DataInputStream;
   21   import java.io.DataOutput;
   22   import java.io.DataOutputStream;
   23   import java.io.IOException;
   24   import java.io.Reader;
   25   import org.apache.activemq.util.ByteArrayInputStream;
   26   import org.apache.activemq.util.ByteArrayOutputStream;
   27   import org.apache.activemq.util.ByteSequence;
   28   import org.apache.activemq.wireformat.WireFormat;
   29   
   30   /**
   31    * Adds the extra methods available to text based wire format implementations
   32    * 
   33    * @version $Revision: 1.1 $
   34    */
   35   public abstract class TextWireFormat implements WireFormat {
   36   
   37       public abstract Object unmarshalText(String text);
   38   
   39       public abstract Object unmarshalText(Reader reader);
   40   
   41       public abstract String marshalText(Object command);
   42   
   43       public void marshal(Object command, DataOutput out) throws IOException {
   44           out.writeUTF(marshalText(command));
   45       }
   46   
   47       public Object unmarshal(DataInput in) throws IOException {
   48           String text = in.readUTF();
   49           return unmarshalText(text);
   50       }
   51   
   52       public ByteSequence marshal(Object command) throws IOException {
   53           ByteArrayOutputStream baos = new ByteArrayOutputStream();
   54           DataOutputStream dos = new DataOutputStream(baos);
   55           marshal(command, dos);
   56           dos.close();
   57           return baos.toByteSequence();
   58       }
   59   
   60       public Object unmarshal(ByteSequence packet) throws IOException {
   61           ByteArrayInputStream stream = new ByteArrayInputStream(packet);
   62           DataInputStream dis = new DataInputStream(stream);
   63           return unmarshal(dis);
   64       }
   65   
   66   	public boolean inReceive() {
   67   		// TODO Implement for inactivity monitor
   68   		return false;
   69   	}
   70       
   71   }

Home » activemq-parent-5.3.1-source-release » org.apache » activemq » transport » util » [javadoc | source]