public Hessian2ObjectOutput(OutputStream os) { mH2o = new Hessian2Output(os); mH2o.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY); }
public void writeFault(String code, String message, Object detail) throws IOException { flushIfFull(); writeVersion(); writeString("code"); writeString(code); writeString("message"); writeString(message); writeString("detail"); writeObject(detail); flushIfFull(); _buffer[_offset++] = (byte) 'Z';
@Override public void flushBuffer() throws IOException { mH2o.flushBuffer(); } }
/** * 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(); }
/** * Starts the streaming message * <p> * <p>A streaming message starts with 'P'</p> * <p> * <pre> * P x02 x00 * </pre> */ public void writeStreamingObject(Object obj) throws IOException { startStreamingPacket(); writeObject(obj); endStreamingPacket(); }
@Override public void close() throws IOException { Hessian2Output out = _out; _out = null; if (out == null) return; _bodyOut.close(); byte[] sig = _mac.doFinal(); out.writeInt(1); out.writeString("signature"); out.writeBytes(sig); out.completeEnvelope(); out.close(); } }
_out.startEnvelope(X509Signature.class.getName()); _out.writeInt(4); _out.writeString("algorithm"); _out.writeString(_algorithm); _out.writeString("fingerprint"); _out.writeBytes(fingerprint); _out.writeString("key-algorithm"); _out.writeString(keyAlgorithm); _out.writeString("key"); _out.writeBytes(encKey); _bodyOut = _out.getBytesOutputStream(); } catch (RuntimeException e) { throw e;
@Override public void close() throws IOException { Hessian2Output out = _out; _out = null; if (out != null) { _deflateOut.close(); _bodyOut.close(); out.writeInt(0); out.completeEnvelope(); out.close(); } } }
@Override public Hessian2Output wrap(Hessian2Output out) throws IOException { OutputStream os = new DeflateOutputStream(out); Hessian2Output filterOut = new Hessian2Output(os); filterOut.setCloseStreamOnClose(true); return filterOut; }
/** * Starts the method call. Clients would use <code>startCall</code> * instead of <code>call</code> if they wanted finer control over * writing the arguments, or needed to write headers. * <p> * <code><pre> * C * string # method name * int # arg count * </pre></code> * * @param method the method name to call. */ @Override public void startCall(String method, int length) throws IOException { int offset = _offset; if (SIZE < offset + 32) { flush(); offset = _offset; } byte[] buffer = _buffer; buffer[_offset++] = (byte) 'C'; writeString(method); writeInt(length); }
private byte[] serializeObject(Object object) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(os); hout.writeObject(object); hout.close(); byte[] result = os.toByteArray(); os.close(); return result; }
public static byte[] encode(Object obj) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(os); h2o.setSerializerFactory(serializerFactory); try { h2o.writeObject(obj); } finally { closeableQuietly(os); closeQuietly(h2o); } return os.toByteArray(); }
/** * <code><pre> * type ::= string * ::= int * </code></pre> */ private void writeType(String type) throws IOException { flushIfFull(); int len = type.length(); if (len == 0) { throw new IllegalArgumentException("empty type is not allowed"); } if (_typeRefs == null) _typeRefs = new HashMap(); Integer typeRefV = (Integer) _typeRefs.get(type); if (typeRefV != null) { int typeRef = typeRefV.intValue(); writeInt(typeRef); } else { _typeRefs.put(type, Integer.valueOf(_typeRefs.size())); writeString(type); } }
@Override public void writeObject(Object obj) throws IOException { mH2o.writeObject(obj); }
DeflateOutputStream(Hessian2Output out) throws IOException { _out = out; _out.startEnvelope(Deflation.class.getName()); _out.writeInt(0); _bodyOut = _out.getBytesOutputStream(); _deflateOut = new DeflaterOutputStream(_bodyOut); }
/** * Writes a byte buffer to the stream. * <p> * <code><pre> * b b16 b18 bytes * </pre></code> */ @Override public void writeByteBufferEnd(byte[] buffer, int offset, int length) throws IOException { writeBytes(buffer, offset, length); }
/** * Writes the tail of the class definition to the stream. */ @Override public void writeClassFieldLength(int len) throws IOException { writeInt(len); }
@Override public void writeFloat(float v) throws IOException { mH2o.writeDouble(v); }
/** * Close the output. */ public void close() throws IOException { _out.close(); } }