@Override public void serialize(final OutputStream output, final Object object) { Hessian2Output ho = new Hessian2Output(output); try { ho.startMessage(); ho.writeObject(object); ho.completeMessage(); ho.close(); output.close(); } catch (IOException e) { e.printStackTrace(); } }
@Override public byte[] serializeMulti(Object[] data) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Hessian2Output out = new Hessian2Output(bos); for(Object obj: data){ out.writeObject(obj); } out.flush(); return bos.toByteArray(); }
/** * @see com.alipay.remoting.serialization.Serializer#serialize(java.lang.Object) */ @Override public byte[] serialize(Object obj) throws CodecException { ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); output.setSerializerFactory(serializerFactory); try { output.writeObject(obj); output.close(); } catch (IOException e) { throw new CodecException("IOException occurred when Hessian serializer encode!", e); } byte[] bytes = byteArray.toByteArray(); return bytes; }
@Override public byte[] serialize(Object msg) throws IOException { Hessian2Output out = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); out = new Hessian2Output(bos); out.writeObject(msg); out.flush(); return bos.toByteArray(); } finally { if(out!=null){ out.close(); } } }
@Override public <T> OutputBuf writeObject(OutputBuf outputBuf, T obj) { Hessian2Output output = Outputs.getOutput(outputBuf); try { output.writeObject(obj); output.flush(); return outputBuf; } catch (IOException e) { ThrowUtil.throwException(e); } finally { try { output.close(); } catch (IOException ignored) {} } return null; // never get here }
public byte[] encode(Object object) throws Exception { ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); output.writeObject(object); output.close(); byte[] bytes = byteArray.toByteArray(); return bytes; }
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; } }
public static Hessian2Output getOutput(OutputStream buf) { return new Hessian2Output(buf); }
/** * Writes a complete method call. */ @Override public void call(String method, Object []args) throws IOException { writeVersion(); int length = args != null ? args.length : 0; startCall(method, length); for (int i = 0; i < length; i++) { writeObject(args[i]); } completeCall(); flush(); }
public Hessian2ObjectOutput(OutputStream os) { hessian2Output = new Hessian2Output(os); hessian2Output.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY); }
/** * Serialize the body to an output stream. */ @Override public void writeBody(OutputStream os) throws IOException { if (_text == null) return; Hessian2Output out = new Hessian2Output(os); out.writeString(_text); out.close(); }
public void close() throws IOException { Hessian2Output out = _out; _out = null; if (out != null) { _deflateOut.close(); _bodyOut.close(); out.writeInt(0); out.completeEnvelope(); out.close(); } } }
public void flush() throws IOException { Hessian2Output out = _out; if (out != null) { out.flush(); } }
/** * Serialize the data */ @Override public void serialize(Object value, OutputStream os) throws IOException { if (log.isLoggable(Level.FINEST)) os = new HessianDebugOutputStream(os, log, Level.FINEST); Hessian2Output hOut = _hessianFactory.createHessian2Output(os); hOut.writeObject(value); hOut.close(); _hessianFactory.freeHessian2Output(hOut); }
/** * Close the output. */ public void close() throws IOException { _out.close(); } }
@Override public void writeObject(Object v) throws IOException { _out.writeObject(v); }
/** * Writes a complete method call. */ @Override public void call(String method, Object []args) throws IOException { int length = args != null ? args.length : 0; startCall(method, length); for (int i = 0; i < args.length; i++) writeObject(args[i]); completeCall(); }
public Hessian2Output wrap(Hessian2Output out) throws IOException { OutputStream os = new DeflateOutputStream(out); Hessian2Output filterOut = new Hessian2Output(os); filterOut.setCloseStreamOnClose(true); return filterOut; }
@Override public byte[] serialize(Object obj) throws SerializerException { ByteArrayOutputStream baos; try { baos = new ByteArrayOutputStream(); Hessian2Output hos = new Hessian2Output(baos); hos.writeObject(obj); hos.flush(); hos.close(); } catch (IOException ex) { throw new SerializerException("Hessian serialize error " + ex.getMessage()); } return baos.toByteArray(); }
@Override public <T> OutputBuf writeObject(OutputBuf outputBuf, T obj) { Hessian2Output output = Outputs.getOutput(outputBuf); try { output.writeObject(obj); output.flush(); return outputBuf; } catch (IOException e) { ThrowUtil.throwException(e); } finally { try { output.close(); } catch (IOException ignored) {} } return null; // never get here }