Beispiel #1
0
  @Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    // System.out.println("decode:" + in.readableBytes());
    if (in.readableBytes() > 4) {
      in.markReaderIndex();
      int needBytes = in.readInt();
      // System.out.println("needBytes:" + needBytes);
      if (in.readableBytes() >= needBytes) {
        byte[] content = new byte[in.readableBytes()];
        in.readBytes(content);
        // byte[] data= ZLipHelper.decompress(content);
        // System.out.println("data:" + new String(data));

        Amf3Input amf3Input = new Amf3Input(SerializationContext.getSerializationContext());
        //				amf3Input = new Amf3Input(SerializationContext.getSerializationContext());
        InputStream bais = new ByteArrayInputStream(content);
        amf3Input.setInputStream(bais);
        try {
          Object decoded = amf3Input.readObject();
          if (decoded != null) {
            out.add(decoded);
            // System.out.println("decoded:" + decoded);
          }
        } catch (Exception e) {
        }
        //				amf3Input.close();
      } else {
        in.resetReaderIndex();
      }
    }
  }
Beispiel #2
0
  //  De-serialize a ByteArray/AMF3/Flex object to a Java object
  protected ASObject deserializeAmf3(InputStream inputStream)
      throws ClassNotFoundException, IOException {
    ASObject deSerializedObj = null;

    SerializationContext context = getSerializationContext();

    Amf3Input amf3Input = new Amf3Input(context);
    amf3Input.setInputStream(inputStream); // uncompress
    deSerializedObj = (ASObject) amf3Input.readObject();
    // amf3Input.close();

    return deSerializedObj;
  }