/** * * @see com.alipay.remoting.serialization.Serializer#deserialize(byte[], java.lang.String) */ @SuppressWarnings("unchecked") @Override public <T> T deserialize(byte[] data, String classOfT) throws CodecException { Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(data)); input.setSerializerFactory(serializerFactory); Object resultObject; try { resultObject = input.readObject(); input.close(); } catch (IOException e) { throw new CodecException("IOException occurred when Hessian serializer decode!", e); } return (T) resultObject; }
@SuppressWarnings("unchecked") @Override public <T> T deserialize(byte[] data, Class<T> clazz) throws Exception { UnsafeByteArrayInputStream bin = new UnsafeByteArrayInputStream(data); Hessian2Input in = new Hessian2Input(bin); in.startMessage(); Object obj = in.readObject(clazz); in.completeMessage(); in.close(); return (T) obj; }
@SuppressWarnings("unchecked") @Override public <T> T deserialize(byte[] data, Class<T> clz) throws IOException { Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(data)); return (T) input.readObject(clz); }
public Object decode(String className,byte[] bytes) throws Exception { Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(bytes)); // avoid child object to parent object problem Object resultObject = input.readObject(); input.close(); return resultObject; }
@Override public <T> T readObject(byte[] bytes, int offset, int length, Class<T> clazz) { Hessian2Input input = Inputs.getInput(bytes, offset, length); try { Object obj = input.readObject(clazz); return clazz.cast(obj); } catch (IOException e) { ThrowUtil.throwException(e); } finally { try { input.close(); } catch (IOException ignored) {} } return null; // never get here }
public static Hessian2Input getInput(byte[] bytes, int offset, int length) { return new Hessian2Input(new ByteArrayInputStream(bytes, offset, length)); }
/** * Read the body from an input stream. */ @Override public void readBody(InputStream is) throws IOException, JMSException { if (is == null) return; Hessian2Input in = new Hessian2Input(is); _text = in.readString(); in.close(); } }
private static Object hessianTransport(Object source, ClassLoader contextClassLoader) { Object target; ClassLoader currentContextClassloader = Thread.currentThread().getContextClassLoader(); try { if (contextClassLoader != null) { Thread.currentThread().setContextClassLoader(contextClassLoader); } SerializerFactory serializerFactory = new SerializerFactory(); serializerFactory.setAllowNonSerializable(true); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(serializerFactory); h2o.writeObject(source); h2o.flush(); byte[] content = bos.toByteArray(); Hessian2Input h2i = new Hessian2Input(new ByteArrayInputStream(content)); h2i.setSerializerFactory(serializerFactory); target = h2i.readObject(); } catch (IOException ex) { throw new RuntimeException(ex); } finally { Thread.currentThread().setContextClassLoader(currentContextClassloader); } return target; } }
/** * Creates a new Hessian 2.0 deserializer. */ public Hessian2Input createHessian2Input(InputStream is) { Hessian2Input in = _freeHessian2Input.allocate(); if (in == null) { in = new Hessian2Input(is); in.setSerializerFactory(getSerializerFactory()); } else { in.init(is); } return in; }
public Hessian2Input unwrapHeaders(Hessian2Input in) throws IOException { InputStream is = new DeflateInputStream(in); Hessian2Input filter = new Hessian2Input(is); filter.setCloseStreamOnClose(true); return filter; }
@SuppressWarnings("unchecked") public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException { return (T) hessian2Input.readObject(cls); }
public void close() throws IOException { Hessian2Input in = _in; _in = null; if (in != null) { _cipherIn.close(); _bodyIn.close(); int len = in.readInt(); if (len != 0) throw new IOException("Unexpected footer"); in.completeEnvelope(); in.close(); } } }
public Hessian2ObjectInput(InputStream is) { hessian2Input = new Hessian2Input(is); hessian2Input.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY); }
public Object []readArguments() throws IOException { int len = readInt(); Object []args = new Object[len]; for (int i = 0; i < len; i++) args[i] = readObject(); return args; }
Hessian2Input in = new Hessian2Input(is); AbstractHessianOutput out; in.setSerializerFactory(serializerFactory); int code = in.read(); int major = in.read(); int minor = in.read();
/** * Close the output. */ public void close() throws IOException { _in.close(); }
public void setSerializerFactory(SerializerFactory factory) { _in.setSerializerFactory(factory); }
@Override public Object[] deserializeMulti(byte[] data, Class<?>[] classes) throws IOException { Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(data)); Object[] objects = new Object[classes.length]; for (int i = 0; i < classes.length; i++) { objects[i] = input.readObject(classes[i]); } return objects; }
@Override public Object decode(String className, byte[] bytes) throws Exception { // TODO Auto-generated method stub Hessian2Input input = new Hessian2Input(new ByteArrayInputStream(bytes)); Object resultObject = input.readObject(); input.close(); return resultObject; }
@Override public <T> T readObject(byte[] bytes, int offset, int length, Class<T> clazz) { Hessian2Input input = Inputs.getInput(bytes, offset, length); try { Object obj = input.readObject(clazz); return clazz.cast(obj); } catch (IOException e) { ThrowUtil.throwException(e); } finally { try { input.close(); } catch (IOException ignored) {} } return null; // never get here }