Search in sources :

Example 11 with HessianSerializerOutput

use of com.caucho.hessian.io.HessianSerializerOutput in project alibaba-rsocket-broker by alibaba.

the class HessianCodecSupport method encode.

public DataBuffer encode(Object obj, DataBufferFactory bufferFactory) throws Exception {
    DataBuffer dataBuffer = bufferFactory.allocateBuffer();
    HessianSerializerOutput output = new HessianSerializerOutput(dataBuffer.asOutputStream());
    output.writeObject(obj);
    output.flush();
    return dataBuffer;
}
Also used : HessianSerializerOutput(com.caucho.hessian.io.HessianSerializerOutput) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Example 12 with HessianSerializerOutput

use of com.caucho.hessian.io.HessianSerializerOutput in project alibaba-rsocket-broker by alibaba.

the class HessianTest method testSerializers.

@Test
public void testSerializers() throws Exception {
    HessianObject hessianObject = new HessianObject();
    hessianObject.setLocalDate(LocalDate.now());
    hessianObject.setLocalDateTime(LocalDateTime.now());
    hessianObject.setLocalTime(LocalTime.now());
    hessianObject.setDuration(Duration.ofSeconds(111));
    hessianObject.setInstant(Instant.now());
    hessianObject.setPeriod(Period.of(1, 3, 16));
    hessianObject.setMonthDay(MonthDay.of(1, 2));
    hessianObject.setYearMonth(YearMonth.of(3, 2));
    hessianObject.setOptional(Optional.of("hello world"));
    hessianObject.setLocale(Locale.CHINESE);
    hessianObject.setUuid(UUID.randomUUID());
    hessianObject.setOffsetTime(OffsetTime.of(1, 2, 13, 11, ZoneOffset.UTC));
    hessianObject.setOffsetDateTime(OffsetDateTime.now());
    hessianObject.setZonedDateTime(ZonedDateTime.now());
    hessianObject.setLongArray(new Long[] { 1L, 3L });
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    HessianSerializerOutput output = new HessianSerializerOutput(bos);
    output.writeObject(hessianObject);
    output.flush();
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    HessianSerializerInput input = new HessianSerializerInput(bis);
    HessianObject hessianObject2 = (HessianObject) input.readObject();
    Assertions.assertThat(hessianObject).isEqualToComparingFieldByField(hessianObject2);
    System.out.println(hessianObject2.getEmojiBear());
}
Also used : HessianSerializerOutput(com.caucho.hessian.io.HessianSerializerOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) HessianSerializerInput(com.caucho.hessian.io.HessianSerializerInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 13 with HessianSerializerOutput

use of com.caucho.hessian.io.HessianSerializerOutput in project alibaba-rsocket-broker by alibaba.

the class ObjectEncodingHandlerHessianImpl method encode.

public static ByteBuf encode(Object obj) throws EncodingException {
    ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer();
    try {
        ByteBufOutputStream bos = new ByteBufOutputStream(byteBuf);
        HessianSerializerOutput output = new HessianSerializerOutput(bos);
        output.writeObject(obj);
        output.flush();
        return byteBuf;
    } catch (Exception e) {
        ReferenceCountUtil.safeRelease(byteBuf);
        throw new EncodingException(RsocketErrorCode.message("RST-700500", obj.getClass().getName(), "byte[]"), e);
    }
}
Also used : HessianSerializerOutput(com.caucho.hessian.io.HessianSerializerOutput) ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) EncodingException(com.alibaba.rsocket.encoding.EncodingException) ByteBuf(io.netty.buffer.ByteBuf) IOException(java.io.IOException) EncodingException(com.alibaba.rsocket.encoding.EncodingException)

Aggregations

HessianSerializerOutput (com.caucho.hessian.io.HessianSerializerOutput)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 Hessian2Output (com.caucho.hessian.io.Hessian2Output)8 Test (org.junit.jupiter.api.Test)7 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)2 EncodingException (com.alibaba.rsocket.encoding.EncodingException)1 HessianSerializerInput (com.caucho.hessian.io.HessianSerializerInput)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1