简体   繁体   中英

How to decompress String in Java which is compressed in VBA using zlib

We are working on a VBA project. In that project we compress the string using zlib.dll and send request to the server. On the server we can't decompress that buffer.

following code which i used in java to uncompress the string

 public static String decompress(byte[] str) throws IOException {
     ByteArrayInputStream bais = new ByteArrayInputStream(str);
        InflaterInputStream iis = new InflaterInputStream(bais);

        String result = "";
        byte[] buf = new byte[5];
        int rlen = -1;
        while ((rlen = iis.read(buf)) != -1) {
            result += new String(Arrays.copyOf(buf, rlen));
        }

        // now result will contain "Hello World!"

        System.out.println("Decompress result: " + result);
        return result;
    }

My Question is how can I decompress the string on the server in Java?

The package java.util.zip provides classes to manage compressed data. java.util.zip.Inflater may be useful in your case.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM