How to read the compressed characters of PHP's Gzencode function output with Java

Source: Internet
Author: User
Keywords PHP java Gzdecode
Phpjavagzdecode

The input string is PHP's Gzencode compressed string, which can be undone with Gzdecode, but is always prompted when reading a string in Java Java.util.zip.GZIPInputStream:
Java.util.zip.ZipException:Not in GZIP format
I hope that experienced friends to help me answer, my code is as follows:

 Javaimport Java.io.bytearrayinputstream;import Java.io.bytearrayoutputstream;import Java.io.InputStream;import Java.io.outputstream;import Java.util.zip.gzipinputstream;import Java.util.zip.gzipoutputstream;public Class Gzdecode {public static void decompress (InputStream is, OutputStream os) throws Exception {Gzipinpu        TStream GIS = new Gzipinputstream (IS);        int count;        byte data[] = new Byte[buffer];        while ((count = gis.read (data, 0, BUFFER))! =-1) {os.write (data, 0, count);    } gis.close (); } public static byte[] Decompress (byte[] data) throws Exception {Bytearrayinputstream Bais = new BYTEARRAYINP          Utstream (data);           Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();           Decompression decompress (Bais, BAOs);          data = Baos.tobytearray ();          Baos.flush ();           Baos.close ();           Bais.close ();      return data; } public static void Main (string[]args) throws Exception {String input= "";        Byte[] Data=input.getbytes ("UTF-8");        Byte[] data_decompress=decompress (data); System.out.write (data_decompress);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.