DataInputStream dis;    if (in instanceof DataInputStream) { dis = (DataInputStream)in; } else { dis = new DataInputStream(in); }
DataInputStream dis = (DataInputStream)(((MessagingObjectInputStream)in).getUnderlyingStream());
   public Object read(InputStream in, Map map) throws IOException, ClassNotFoundException   {            if (in instanceof JBossObjectInputStream)      {         // Need to explicitly set the classloader         ((JBossObjectInputStream)in).            setClassLoader(Thread.currentThread().getContextClassLoader());      }            DataInputStream dis;            //TODO We should ensure that remoting always passes in a DataInputStream      //This saves us wrapping it each time      if (in instanceof DataInputStream)      {         dis = (DataInputStream)in;      }      else      {         dis = new DataInputStream(in);      }      // First byte read is always version      byte version = dis.readByte();      byte formatType = (byte)dis.read();      if (trace) { log.trace("reading, format type is " + formatType); }            try      {            switch (formatType)         {            case SERIALIZED:            {               // Delegate to serialization               Object ret = serializableUnMarshaller.read(dis, map);                  if (trace) { log.trace("read using standard serialization"); }                  return ret;            }            case SEND:            {               MethodInvocation mi = readHeader(dis);                  byte messageType = dis.readByte();                  JBossMessage m = (JBossMessage)MessageFactory.createMessage(messageType);                  m.read(dis);                  Object[] args = new Object[] {m};                  mi.setArguments(args);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read send()"); }                  return request;            }            case MORE:            {               MethodInvocation mi = readHeader(dis);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read activate()"); }                  return request;            }                     case SEND_TRANSACTION:            {               MethodInvocation mi = readHeader(dis);                  TransactionRequest tr = new TransactionRequest();                  tr.read(dis);                  Object[] args = new Object[] {tr};                  mi.setArguments(args);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read sendTransaction()"); }                  return request;            }            case GET_ID_BLOCK:            {               MethodInvocation mi = readHeader(dis);                  int size = dis.readInt();                  Object[] args = new Object[] {new Integer(size)};                  mi.setArguments(args);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read getIdBlock()"); }                  return request;            }            case ACKNOWLEDGE:            {               MethodInvocation mi = readHeader(dis);                              AckInfo info = new AckInfo();                              info.read(dis);                              Object[] args = new Object[] {info};                  mi.setArguments(args);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read acknowledge()"); }                  return request;            }            case ACKNOWLEDGE_BATCH:            {               MethodInvocation mi = readHeader(dis);                                          int num = dis.readInt();                              List acks = new ArrayList(num);                              for (int i = 0; i < num; i++)               {                  AckInfo ack = new AckInfo();                                    ack.read(dis);                                    acks.add(ack);               }                                          Object[] args = new Object[] {acks};                  mi.setArguments(args);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read acknowledge()"); }                  return request;            }            case CANCEL_DELIVERIES:            {               MethodInvocation mi = readHeader(dis);                  int size = dis.readInt();                  List acks = new ArrayList(size);                  for (int i = 0; i < size; i++)               {                  AckInfo ack = new AckInfo();                                    ack.read(dis);                                    acks.add(ack);               }                  Object[] args = new Object[] {acks};                  mi.setArguments(args);                  InvocationRequest request =                  new InvocationRequest(null, ServerPeer.REMOTING_JMS_SUBSYSTEM,                                        new MessagingMarshallable(version, mi), null, null, null);                  if (trace) { log.trace("read cancelDeliveries()"); }                  return request;            }            case ID_BLOCK_RESPONSE:            {               IdBlock block = new IdBlock();                  block.read(dis);                  InvocationResponse resp = new InvocationResponse(null, new MessagingMarshallable(version, block), false, null);                  if (trace) { log.trace("read id block response"); }                  return resp;            }            case HANDLE_MESSAGE_RESPONSE:            {               HandleMessageResponse res = new HandleMessageResponse();                  res.read(dis);                  InvocationResponse resp = new InvocationResponse(null, new MessagingMarshallable(version, res), false, null);                  if (trace) { log.trace("read handle message response"); }                  return resp;            }            case NULL_RESPONSE:            {                   InvocationResponse resp =                  new InvocationResponse(null, new MessagingMarshallable(version, null), false, null);                  if (trace) { log.trace("read null response"); }                  return resp;            }            case CALLBACK:            {               ClientDelivery dr = new ClientDelivery();                              dr.read(dis);                  InvocationRequest request =                  new InvocationRequest(null, CallbackServerFactory.JMS_CALLBACK_SUBSYSTEM,                                        new MessagingMarshallable(version, dr), null, null, null);                  if (trace) { log.trace("read callback()"); }                  return request;            }            default:            {               throw new IllegalStateException("Invalid format type " + formatType);            }         }      }      catch (Exception e)      {         IOException e2 = new IOException(e.getMessage());         e2.setStackTrace(e.getStackTrace());         throw e2;      }   }