2010-12-01 4 views
1

PHP gzcompress() 함수로 압축 된 String을 어떻게 압축 해제 할 수 있습니까?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) 문자열의 압축을 풀려고하면 제대로 동작하지 않습니다 :

들으

나는 이런 식으로 지금을 시도했다. DEFLATE 알고리즘은 GZIP이기 때문에

답변

2

GZIPInputStream을 사용해보십시오. this examplethis SO question을 참조하십시오. GZIP 알고리즘을 수축 사용하지만 DEFLATE은 단지 데이터를 압축 이후 또한, 헤더 정보 (파일 이름이 압축되는 것처럼, 파일 사용 권한)의 비트를 추가

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

여기서 작동하지 않습니다. –