Java Code Examples for com.alibaba.com.caucho.hessian.io.Hessian2Output#flush()

The following examples show how to use com.alibaba.com.caucho.hessian.io.Hessian2Output#flush() . 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: DubboResponseBody.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
public byte[] encodeResponseBody() throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(DubboConstants.DEFAULT_OUTPUT_BUFFER_SIZE);
    Hessian2Output hessian2Output = new Hessian2Output(outputStream);
    hessian2Output.setSerializerFactory(DubboRequestBody.SERIALIZER_FACTORY);
    hessian2Output.writeInt(responseType);
    hessian2Output.writeObject(result);
    if (attachments != null && attachments.size() > 0) {
        hessian2Output.writeObject(attachments);
    }
    hessian2Output.flush();
    return outputStream.toByteArray();
}
 
Example 2
Source File: DubboResponseBody.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
public static byte[] encodeErrorResponseBody(String errorMessage) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Hessian2Output hessian2Output = new Hessian2Output(outputStream);
    hessian2Output.setSerializerFactory(DubboRequestBody.SERIALIZER_FACTORY);
    hessian2Output.writeString(errorMessage);
    hessian2Output.flush();
    byte[] bodyBytes = outputStream.toByteArray();
    return bodyBytes;
}
 
Example 3
Source File: DubboResponseBody.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
public static byte[] encodeHeartbeatResponseBody() throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Hessian2Output hessian2Output = new Hessian2Output(outputStream);
    hessian2Output.setSerializerFactory(DubboRequestBody.SERIALIZER_FACTORY);
    hessian2Output.writeString(DubboConstants.HEARTBEAT_EVENT);
    hessian2Output.flush();
    byte[] bodyBytes = outputStream.toByteArray();
    return bodyBytes;
}
 
Example 4
Source File: Java8TimeSerializerTest.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
private void testJava8Time(Object expected) throws IOException {
    os.reset();

    Hessian2Output output = new Hessian2Output(os);
    output.setSerializerFactory(factory);
    output.writeObject(expected);
    output.flush();

    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
    Hessian2Input input = new Hessian2Input(is);
    input.setSerializerFactory(factory);
    Object actual = input.readObject();

    TestCase.assertEquals(expected, actual);
}
 
Example 5
Source File: SerializeTestBase.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
/**
 * hessian2 serialize util
 *
 * @param data
 * @param <T>
 * @return
 * @throws IOException
 */
protected <T> T baseHessian2Serialize(T data) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Hessian2Output out = new Hessian2Output(bout);

    out.writeObject(data);
    out.flush();

    ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
    Hessian2Input input = new Hessian2Input(bin);
    return (T) input.readObject();
}