Java Code Examples for com.caucho.hessian.io.AbstractHessianInput#readObject()

The following examples show how to use com.caucho.hessian.io.AbstractHessianInput#readObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDateTimeDeserializer.java    From jvm-sandbox-repeater with Apache License 2.0 6 votes vote down vote up
@Override
public Object readObject(AbstractHessianInput in,
                         Object[] fields)
        throws IOException {

    String[] fieldNames = (String[]) fields;

    int ref = in.addRef(null);

    long initValue = Long.MIN_VALUE;

    for (int i = 0; i < fieldNames.length; i++) {
        String key = fieldNames[i];
        if ("value".equals(key)) {
            initValue = in.readUTCDate();
        } else {
            in.readObject();
        }
    }
    Object value = create(initValue);
    in.setRef(ref, value);
    return value;
}
 
Example 2
Source File: GenericClassDeserializer.java    From sofa-hessian with Apache License 2.0 6 votes vote down vote up
/**
 * 当读取Object时会调用此方法, Object类型包括Enum与AliEnum
 */
public Object readObject(AbstractHessianInput in, Object[] fieldNames) throws IOException {
    int ref = in.addRef(null);

    String name = null;

    for (int i = 0; i < fieldNames.length; i++) {
        if ("name".equals(fieldNames[i])) {
            name = in.readString();
        } else {
            in.readObject();
        }
    }

    Object value;
    if (ClassFilter.filter(name)) {
        value = create(name);
    } else {
        value = new GenericClass(name);
    }

    in.setRef(ref, value);

    return value;
}
 
Example 3
Source File: TranscribableEnumDeserializer.java    From cougar with Apache License 2.0 6 votes vote down vote up
public Object readMap(AbstractHessianInput in) throws IOException {
    String name = null;

    while (!in.isEnd()) {
        String key = in.readString();

        if (key.equals("name")) {
            name = in.readString();
        }
        else {
            in.readObject();
        }
    }

    in.readMapEnd();

    Object obj = transcriptionParams.contains(TranscribableParams.EnumsWrittenAsStrings) ? name : create(name);

    in.addRef(obj);

    return obj;
}
 
Example 4
Source File: TranscribableEnumDeserializer.java    From cougar with Apache License 2.0 6 votes vote down vote up
@Override
public Object readObject(AbstractHessianInput in, Object[] fields) throws IOException {
    String[] fieldNames = (String[]) fields;
    String name = null;

    for (int i = 0; i < fieldNames.length; i++) {
        if ("name".equals(fieldNames[i])) {
            name = in.readString();
        }
        else {
            in.readObject();
        }
    }

    Object obj = create(name);

    in.addRef(obj);

    return obj;
}
 
Example 5
Source File: FaultDetailDeserialiser.java    From cougar with Apache License 2.0 6 votes vote down vote up
@Override
public Object readObject(final AbstractHessianInput in, Object[] fields) throws IOException {

	try {

		TranscriptionInput ti = new TranscriptionInput() {

			@Override
			public <T> T readObject(Parameter param, boolean client) throws Exception {
				return (T) in.readObject();
			}
		};

		int ref = in.addRef(null);

           FaultDetail o = transcribe(ti);
           in.setRef(ref, o);

		return o;
	}
	catch (Exception e) {
		throw new IOException(e);
	}

}
 
Example 6
Source File: MBeanNotificationInfoDeserializer.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
public Object readMap(AbstractHessianInput in)
    throws IOException
{
    String name = null;
    String description = null;
    String[] types = null;

    while (!in.isEnd()) {
        String key = in.readString();

        if ("name".equals(key))
            name = in.readString();
        else if ("description".equals(key))
            description = in.readString();
        else if ("types".equals(key))
            types = (String[]) in.readObject(String[].class);
        else {
            in.readObject();
        }
    }

    in.readMapEnd();

    try {
        MBeanNotificationInfo info;

        info = new MBeanNotificationInfo(types, name, description);

        return info;
    } catch (Exception e) {
        throw new IOException(String.valueOf(e));
    }
}
 
Example 7
Source File: HessianSerializerUtils.java    From zkdoctor with Apache License 2.0 5 votes vote down vote up
/**
 * 反序列化
 *
 * @param bytes 待反序列化字节数组
 * @return
 */
public static Object deserialize(byte[] bytes) {
    ByteArrayInputStream ips = new ByteArrayInputStream(bytes);
    AbstractHessianInput in = new Hessian2Input(ips);
    in.setSerializerFactory(new SerializerFactory());
    Object value;
    try {
        value = in.readObject();
        in.close();
    } catch (IOException e) {
        LOGGER.error("Hessian deserialize failed", e);
        throw new RuntimeException("Hessian deserialize failed");
    }
    return value;
}
 
Example 8
Source File: HessianBase.java    From marshalsec with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see marshalsec.MarshallerBase#unmarshal(java.lang.Object)
 */
@Override
public Object unmarshal ( byte[] data ) throws Exception {
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    AbstractHessianInput in = createInput(bis);
    return in.readObject();
}
 
Example 9
Source File: HessianSerializer.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(final byte[] bytes, final Type returnType) throws Exception {
    if (null == bytes || bytes.length == 0) {
        return null;
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
    AbstractHessianInput input = new Hessian2Input(inputStream);
    input.setSerializerFactory(SERIALIZER_FACTORY);
    Object obj = input.readObject();
    input.close();
    return obj;
}
 
Example 10
Source File: TranscribableExceptionDeserialiser.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Override
public Object readObject(final AbstractHessianInput in, Object[] fields) throws IOException {

	try {

		TranscriptionInput ti = new TranscriptionInput() {

			@Override
			public <T> T readObject(Parameter param, boolean client) throws Exception {
				return (T) in.readObject();
			}
		};

		int ref = in.addRef(null);

		Constructor constructor = cls.getConstructor(TranscriptionInput.class, Set.class);
           Object ret = constructor.newInstance(ti, transcriptionParams);

           in.setRef(ref, ret);

		return ret;
	}
	catch (Exception e) {
		throw new IOException(e);
	}

}
 
Example 11
Source File: MBeanInfoDeserializer.java    From jvm-sandbox-repeater with Apache License 2.0 4 votes vote down vote up
public Object readMap(AbstractHessianInput in)
  throws IOException
{
  String className = null;
  String description = null;
  MBeanAttributeInfo []attributes = null;
  MBeanConstructorInfo []constructors = null;
  MBeanOperationInfo []operations = null;
  MBeanNotificationInfo []notifications = null;
  
  while (! in.isEnd()) {
    String key = in.readString();

    if ("className".equals(key))
      className = in.readString();
    else if ("description".equals(key))
      description = in.readString();
    else if ("attributes".equals(key)) {
      attributes = (MBeanAttributeInfo []) in.readObject(MBeanAttributeInfo[].class);
    }
    /*
    else if ("isWrite".equals(key))
      isWrite = in.readBoolean();
    else if ("isIs".equals(key))
      isIs = in.readBoolean();
    */
    else
      in.readObject();
  }

  in.readMapEnd();

  try {
    MBeanInfo info;
    
    info = new MBeanInfo(className, description, attributes,
                         constructors, operations, notifications);

    return info;
  } catch (Exception e) {
    throw new IOException(String.valueOf(e));
  }
}