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;
}
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());
}
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);
}
}
Aggregations