存档

文章标签 ‘GZIPOutputStream’

gzip在Android4.4下面崩溃的问题

2013年12月11日 3 条评论

最近在搞的一个项目,在Android 4.4(API 19)下,gzip会崩溃。
相关的调用代码如下:

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gos = null;
        try {
            gos = new GZIPOutputStream(baos);
            gos.write(srcData);
            gos.finish();
            gos.flush();//这里会崩溃
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            gos.close();
        }

崩溃时的日志如下:

11-25 15:33:13.757: E/AndroidRuntime(10723): FATAL EXCEPTION
11-25 15:33:13.757: E/AndroidRuntime(10723): Process: com.xxxxx, PID: 10723
11-25 15:33:13.757: E/AndroidRuntime(10723): java.util.zip.DataFormatException: stream error
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at java.util.zip.Deflater.deflateImpl(Native Method)
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at java.util.zip.Deflater.deflateImpl(Deflater.java:241)
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at java.util.zip.Deflater.deflate(Deflater.java:232)
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at java.util.zip.DeflaterOutputStream.flush(DeflaterOutputStream.java:193)
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at com.xxxxx.xx.Xxx.compress(Xxx.java:727)
...此处略去N行无关信息
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at android.os.Looper.loop(Looper.java:137)
11-25 15:33:13.757: E/AndroidRuntime(10723): 	at android.os.HandlerThread.run(HandlerThread.java:61)

更多内容…