2010-12-01 31 views
1

PHPのgzcompress()関数で圧縮された文字列をどのように解凍できますか?Android:PHPで圧縮された文字列を解凍するgzcompress()

完全な例ですか?

public static String unzipString(String zippedText) throws Exception 
{ 
    ByteArrayInputStream bais = new ByteArrayInputStream(zippedText.getBytes("UTF-8")); 
    GZIPInputStream gzis = new GZIPInputStream(bais); 
    InputStreamReader reader = new InputStreamReader(gzis); 
    BufferedReader in = new BufferedReader(reader); 

    String unzipped = ""; 
    while ((unzipped = in.readLine()) != null) 
     unzipped+=unzipped; 

    return unzipped; 
} 

しかし、私はPHPのgzcompress(-ed)文字列を解凍しようとしているならば、それは働いていない:

THX

は、私はこのように今それを試してみました。 deflateアルゴリズムはgzipであるので、

答えて

2

GZIPInputStreamを試してください。 this exampleおよびthis SO questionを参照してください。 GZIPアルゴリズムを収縮使用していますが、デフレートだけでデータを圧縮するので、それはまた、ヘッダ情報(ファイルの名前が圧縮されているように、ファイルのパーミッション)のビットを追加します。

7

PHPのgzcompressはZlibの、NOT GZIP

public static String unzipString(String zippedText) { 
    String unzipped = null; 
    try { 
     byte[] zbytes = zippedText.getBytes("ISO-8859-1"); 
     // Add extra byte to array when Inflater is set to true 
     byte[] input = new byte[zbytes.length + 1]; 
     System.arraycopy(zbytes, 0, input, 0, zbytes.length); 
     input[zbytes.length] = 0; 
     ByteArrayInputStream bin = new ByteArrayInputStream(input); 
     InflaterInputStream in = new InflaterInputStream(bin); 
     ByteArrayOutputStream bout = new ByteArrayOutputStream(512); 
     int b; 
     while ((b = in.read()) != -1) { 
      bout.write(b); } 
     bout.close(); 
     unzipped = bout.toString(); 
    } 
    catch (IOException io) { printIoError(io); } 
    return unzipped; 
} 
private static void printIoError(IOException io) 
{ 
    System.out.println("IO Exception: " + io.getMessage()); 
} 
+0

Characterset RFC 1951を渡すとエラーが発生するjava.io.UnsupportedEncodingException:RFC 1951 –

+0

ここでは動作しない –

関連する問題