@Test public void testDecode() throws Exception { SwallowMessage msg = new SwallowMessage(); msg.setGeneratedTime(new Date()); msg.setMessageId(123L); HashMap<String, String> map = new HashMap<String, String>(); map.put("property-key", "property-value"); msg.setContent("content"); ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(factory); h2o.writeObject(msg); h2o.flush(); h2o.close(); byte[] content = bos.toByteArray(); HessianDecoder hessianDecoder = new HessianDecoder(); Message actualMsg = (Message) hessianDecoder.decode(null, null, ChannelBuffers.wrappedBuffer(content)); Assert.assertEquals(msg, actualMsg); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; if (buf.hasArray()) { ByteArrayInputStream bis = new ByteArrayInputStream(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes()); Hessian2Input in = new Hessian2Input(bis); in.setSerializerFactory(factory); return in.readObject(Message.class); } else { Hessian2Input in = new Hessian2Input(new ChannelBufferInputStream((ChannelBuffer) msg)); in.setSerializerFactory(factory); return in.readObject(Message.class); } }
HessianDecoder extends OneToOneDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; if (buf.hasArray()) { ByteArrayInputStream bis = new ByteArrayInputStream(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes()); Hessian2Input in = new Hessian2Input(bis); in.setSerializerFactory(factory); return in.readObject(Message.class); } else { Hessian2Input in = new Hessian2Input(new ChannelBufferInputStream((ChannelBuffer) msg)); in.setSerializerFactory(factory); return in.readObject(Message.class); } } }
HessianDecoder extends OneToOneDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; if (buf.hasArray()) { ByteArrayInputStream bis = new ByteArrayInputStream(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes()); Hessian2Input in = new Hessian2Input(bis); in.setSerializerFactory(factory); return in.readObject(Message.class); } else { Hessian2Input in = new Hessian2Input(new ChannelBufferInputStream((ChannelBuffer) msg)); in.setSerializerFactory(factory); return in.readObject(Message.class); } } HessianDecoder(); }
HessianDecoder extends OneToOneDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; if (buf.hasArray()) { ByteArrayInputStream bis = new ByteArrayInputStream(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes()); Hessian2Input in = new Hessian2Input(bis); in.setSerializerFactory(factory); return in.readObject(Message.class); } else { Hessian2Input in = new Hessian2Input(new ChannelBufferInputStream((ChannelBuffer) msg)); in.setSerializerFactory(factory); return in.readObject(Message.class); } } HessianDecoder();  }
HessianDecoder extends OneToOneDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer buf = (ChannelBuffer) msg; if (buf.hasArray()) { ByteArrayInputStream bis = new ByteArrayInputStream(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes()); Hessian2Input in = new Hessian2Input(bis); in.setSerializerFactory(factory); return in.readObject(Message.class); } else { Hessian2Input in = new Hessian2Input(new ChannelBufferInputStream((ChannelBuffer) msg)); in.setSerializerFactory(factory); return in.readObject(Message.class); } } HessianDecoder();   }