⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectinputstreammicro.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
字号:
/*------------------------------------------------------------------------------Name:      ObjectInputStreamMicro.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.client.protocol.http.common;import java.io.DataInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Hashtable;import java.util.Vector;/** * ObjectInputStreamMicro * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a> */public class ObjectInputStreamMicro implements I_ObjectStream {   private DataInputStream in;   public ObjectInputStreamMicro(InputStream inStream) throws IOException {      this.in = new DataInputStream(inStream);          }      private Hashtable readHashtable() throws IOException {      int size = this.in.readInt();      Hashtable ret = new Hashtable();      for (int i=0; i < size; i++) {         String key = this.in.readUTF();         String val = this.in.readUTF();         ret.put(key, val);      }      return ret;   }   private Vector readVector() throws IOException {      int size = this.in.readInt();      Vector ret = new Vector();      for (int i=0; i < size; i++) {         ret.addElement(readHashtable());         ret.addElement(readHashtable());         int length = this.in.readInt();         byte[] content = new byte[length];         this.in.read(content);         ret.addElement(content);      }      return ret;   }   public Object readObject() throws IOException, ClassNotFoundException {      int code = this.in.readInt();      if (code == STRING) {         return this.in.readUTF();      }      else if (code == HASHTABLE) {         return readHashtable();      }      else if (code == HASHTABLE_ARR) {         int size  = this.in.readInt();         Hashtable[] ret = new Hashtable[size];         for (int i=0; i < size; i++) {            ret[i] = readHashtable();         }         return ret;      }      else if (code == VECTOR) {         return readVector();      }      else {         StringBuffer buf = new StringBuffer();         buf.append("object of type with code='").append(code).append("' is not supported");         throw new IOException(buf.toString());      }   }   /**    *     * @param buffer the buffer from which to read the message    * @return the MsgHolder object.    * If one of the parameters was null or empty before serialization, it    * will be null here after reading it from the buffer.    * @throws IOException    */   public static MsgHolder readMessage(byte[] buffer) throws IOException {      if (buffer.length < 4) return new MsgHolder(null, null, null, null);            int pos = 0, i = pos;      while (buffer[i] != 0) i++;      String oid = ((i == 0) ? (String)null : new String(buffer, 0, i));      pos = ++i;      while (buffer[i] != 0) i++;      String key = new String(buffer, pos, i-pos);      if (key.length() < 1) key = null;      pos = ++i;      while (buffer[i] != 0) i++;      String qos = new String(buffer, pos, i-pos);      if (qos.length() < 1) qos = null;      pos = ++i;      byte[] content = new byte[buffer.length-pos];      while (i < buffer.length) {         content[i-pos] = buffer[i];         i++;      }      return new MsgHolder(oid, key, qos, content);   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -