Exemple #1
0
 private static Object readRealObject(byte type, InputStream is, ClassLoader loader)
     throws IOException {
   try {
     if (type == 0) {
       return PDataStream.readUTF(is);
     } else if (type == 1) {
       return new Integer(PDataStream.readInt(is));
     } else if (type == 2) {
       return new Long(PDataStream.readLong(is));
     } else if (type == 3) {
       return new Byte((byte) is.read());
     } else if (type == 4) {
       return PDataStream.readBoolean(is) ? Boolean.TRUE : Boolean.FALSE;
     } else if (type == 5) {
       return new Character(PDataStream.readChar(is));
     } else if (type == 6) {
       return new Short(PDataStream.readShort(is));
     } else if (type == 7) {
       return new Float(PDataStream.readFloat(is));
     } else if (type == 8) {
       return new Double(PDataStream.readDouble(is));
     } else if (type == 11) {
       String name = PDataStream.readUTF(is);
       Class c = loader == null ? Class.forName(name) : loader.loadClass(name);
       if (Externalizable.class.isAssignableFrom(c)) {
         Externalizable obj = (Externalizable) c.newInstance();
         obj.readObject(is);
         return obj;
       }
       throw new IOException("Could not read object " + name);
     } else if (type == 12) {
       ObjectInputStream in =
           loader == null
               ? new ObjectInputStream(is)
               : (ObjectInputStream) new XObjectInputStream(loader, is);
       return in.readObject();
     }
   } catch (ClassNotFoundException cnfe) {
     throw new IOException("Could not find class " + cnfe.toString());
   } catch (Exception exc) {
     throw exc instanceof IOException
         ? (IOException) exc
         : new IOException("Could not read object " + exc.toString());
   }
   throw new IllegalArgumentException("Unsupported Typed Object: " + type);
 }