Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
    int length = data.getInt();

    Collection collection;
    try {
      collection = (Collection) c.newInstance();
    } catch (Exception e) {
      log.log(
          Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList.");
      collection = new ArrayList(length);
    }

    if (length == 0) return (T) collection;

    if (data.get() == (byte) 1) {
      SerializerRegistration reg = Serializer.readClass(data);
      Class clazz = reg.getType();
      Serializer serializer = reg.getSerializer();

      for (int i = 0; i != length; ++i) {
        collection.add(serializer.readObject(data, clazz));
      }
    } else {
      for (int i = 0; i != length; ++i) {
        collection.add(Serializer.readClassAndObject(data));
      }
    }
    return (T) collection;
  }
Ejemplo n.º 2
0
 /** Creates a message from the properly sized byte buffer and adds it to the messages queue. */
 protected void createMessage(ByteBuffer buffer) {
   try {
     Object obj = Serializer.readClassAndObject(buffer);
     Message m = (Message) obj;
     messages.add(m);
   } catch (IOException e) {
     throw new RuntimeException("Error deserializing object", e);
   }
 }