com.caucho.hessian.io.AbstractHessianInput Java Examples

The following examples show how to use com.caucho.hessian.io.AbstractHessianInput. 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: 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 #2
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 #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: 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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: MyListDeserializer.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
void deserialize(AbstractHessianInput in, Object obj) throws IOException {
    String value = null;

    try {
        value = in.readString();

        _field.set(obj, value);
    } catch (Exception e) {
        logDeserializeError(_field, obj, value, e);
    }
}
 
Example #11
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 #12
Source File: MyListDeserializer.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
public Object readObject(AbstractHessianInput in, Object[] fieldNames) throws IOException {
    return readObject(in, (String[]) fieldNames);
}
 
Example #13
Source File: HessianSkeleton.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
/**
 * Invoke the object with the request from the input stream.
 *
 * @param in the Hessian input stream
 * @param out the Hessian output stream
 */
public void invoke(InputStream is, OutputStream os,
                   SerializerFactory serializerFactory)
    throws Exception
{
    boolean isDebug = false;

    if (isDebugInvoke()) {
        isDebug = true;

        PrintWriter dbg = createDebugPrintWriter();
        HessianDebugInputStream dIs = new HessianDebugInputStream(is, dbg);
        dIs.startTop2();
        is = dIs;
        HessianDebugOutputStream dOs = new HessianDebugOutputStream(os, dbg);
        dOs.startTop2();
        os = dOs;
    }

    HessianInputFactory.HeaderType header = _inputFactory.readHeader(is);

    AbstractHessianInput in;
    AbstractHessianOutput out;

    switch (header) {
        case CALL_1_REPLY_1:
            in = _hessianFactory.createHessianInput(is);
            out = _hessianFactory.createHessianOutput(os);
            break;

        case CALL_1_REPLY_2:
            in = _hessianFactory.createHessianInput(is);
            out = _hessianFactory.createHessian2Output(os);
            break;

        case HESSIAN_2:
            in = _hessianFactory.createHessian2Input(is);
            in.readCall();
            out = _hessianFactory.createHessian2Output(os);
            break;

        default:
            throw new IllegalStateException(header + " is an unknown Hessian call");
    }

    if (serializerFactory != null) {
        in.setSerializerFactory(serializerFactory);
        out.setSerializerFactory(serializerFactory);
    }

    try {
        invoke(_service, in, out);
    } finally {
        in.close();
        out.close();

        if (isDebug)
            os.close();
    }
}
 
Example #14
Source File: TranscribableEnumDeserializer.java    From cougar with Apache License 2.0 4 votes vote down vote up
public Object readObject(AbstractHessianInput in) throws IOException {
    return in.readString();
}
 
Example #15
Source File: HessianProxyFactory.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
public AbstractHessianInput getHessianInput(InputStream is)
{
    return getHessian2Input(is);
}
 
Example #16
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));
  }
}
 
Example #17
Source File: Hessian.java    From marshalsec with MIT License 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see marshalsec.AbstractHessianBase#createInput(java.io.ByteArrayInputStream)
 */
@Override
protected AbstractHessianInput createInput ( ByteArrayInputStream bos ) {
    return new HessianInput(bos);
}
 
Example #18
Source File: Burlap.java    From marshalsec with MIT License 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see marshalsec.AbstractHessianBase#createInput(java.io.ByteArrayInputStream)
 */
@Override
protected AbstractHessianInput createInput ( ByteArrayInputStream bos ) {
    return new BurlapInput(bos);
}
 
Example #19
Source File: HessianSkeleton.java    From sofa-hessian with Apache License 2.0 2 votes vote down vote up
/**
 * Invoke the object with the request from the input stream.
 *
 * @param in the Hessian input stream
 * @param out the Hessian output stream
 */
public void invoke(AbstractHessianInput in, AbstractHessianOutput out)
    throws Exception
{
    invoke(_service, in, out);
}
 
Example #20
Source File: MyListDeserializer.java    From sofa-hessian with Apache License 2.0 votes vote down vote up
abstract void deserialize(AbstractHessianInput in, Object obj) throws IOException; 
Example #21
Source File: HessianBase.java    From marshalsec with MIT License votes vote down vote up
protected abstract AbstractHessianInput createInput ( ByteArrayInputStream bos );