我通过jpcap抓获网络中传输的gzip加密数据包,通过GZIPInputStream进行解压,结果英文能正常解压出来,中文解压出来的是乱码。求高人指点

解决方案 »

  1.   

    // 建立grip压缩文件输入流
    InputStream fin = new ByteArrayInputStream(contentbyte); /**
     * 测试时候进入gzip解码
     */
    System.out.println("\n\n\n\nGZIP!\n\n\n\n"); try {
    // 建立gzip解压工作流
    GZIPInputStream gzin = new GZIPInputStream(fin); byte[] buf = new byte[1024];
    ArrayList<byte[]> cb = new ArrayList<byte[]>();
    int num, len = 0;
    while ((num = gzin.read(buf, 0, buf.length)) != -1) {
    byte[] cell = new byte[num];
    len += num;
    System.arraycopy(buf, 0, cell, 0, num);
    cb.add(cell);
    }
    contentbyte = new byte[len];
    num = 0;
    for (byte[] c : cb) {
    System.arraycopy(c, 0, contentbyte, num, c.length);
    num += c.length;
    } gzin.close();
    fin.close();
      

  2.   

    contentbyte里面存储的是网上传输的网页内容,包括英文字符,还有中文字符。
      

  3.   

    将contentbyte的内容转字符串时,有指定编码么?
      

  4.   

    写一个Character过滤器,搞定一切乱码.