All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.icodegarden.nutrient.lang.serialization.Hessian2Deserializer Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package io.github.icodegarden.nutrient.lang.serialization;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import com.caucho.hessian.io.Hessian2Input;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author Fangfang.Xu
 *
 */
@Slf4j
public class Hessian2Deserializer implements Deserializer {

	@Override
	public Object deserialize(byte[] bytes) throws SerializationException {
		ByteArrayInputStream is = new ByteArrayInputStream(bytes);
		Hessian2Input input = new Hessian2Input(is);
		input.setSerializerFactory(Hessian2Serializer.serializerFactory);
		try {
			return input.readObject();
		} catch (Throwable e) {
			throw new SerializationException("Error when deserializing byte[] to object", e);
		} finally {
			try {
				input.close();
			} catch (IOException e) {
				log.error("ex on close hessian2 input", e);
			}
		}
	}
}