Java decompressing array of bytes

前端 未结 2 567
悲&欢浪女
悲&欢浪女 2021-01-22 12:10

On server (C++), binary data is compressed using ZLib function:

compress2()

and it\'s sent over to client (Java). On client side (

2条回答
  •  悲哀的现实
    2021-01-22 12:30

    I think the problem is not with unpack method but in packedBuffer content. Unpack works fine

    public static byte[] pack(String s) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DeflaterOutputStream dout = new DeflaterOutputStream(out);
        dout.write(s.getBytes());
        dout.close();
        return out.toByteArray();
    }
    
    public static void main(String[] args) throws Exception {
        byte[] a = pack("123");
        String s = unpack(a);   // calls your unpack
        System.out.println(s);
    }
    

    output

    123
    

提交回复
热议问题