从GZIPInputStream截断输出在Android [英] truncated output from GZIPInputStream on Android

查看:129
本文介绍了从GZIPInputStream截断输出在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做一些真的错了。以下运行在Android code它会产生截断的文件(_items_),而不在日志中的任何异常或问题。与OpenJDK 7的运行相同code将其DECOM $ P $正确psses文件。

I must be doing something really wrong. Running following code on Android it produces truncated file (_items_) without any exceptions or problems in the log. Running the same code with OpenJDK 7 it decompresses the file correctly.

try {
    final InputStream fis = new GZIPInputStream(new FileInputStream("/storage/sdcard/_items"));
    try {
        final FileOutputStream fos = new FileOutputStream("/storage/sdcard/_items_");
        try {
            final byte[] buffer = new byte[1024];
            int n;
            while ((n = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, n);
            }
        } finally {
            fos.close();
        }
    } finally {
        fis.close();
    }
} catch (final IOException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
}

我已经与Android模拟器(API 18)和Desire HD的(Android的2.3.5)与同车的结果试过这一点。

I've tried this with Android emulator (API 18) and on Desire HD (Android 2.3.5) with the same buggy result.

输入文件(_items): https://drive.google。 COM /文件/ D / 0B6M72P2gzYmwaHg4SzRTYnRMOVk /编辑?USP =共享

Input file (_items): https://drive.google.com/file/d/0B6M72P2gzYmwaHg4SzRTYnRMOVk/edit?usp=sharing

Android的截断输出文件(_items_): https://开头的车程。 google.com/file/d/0B6M72P2gzYmwMUZIZ2FEaHNZUFk/edit?usp=sharing

Android truncated output file (_items_): https://drive.google.com/file/d/0B6M72P2gzYmwMUZIZ2FEaHNZUFk/edit?usp=sharing

推荐答案

解决方法是使用 GZIPInputStream 从JZlib(目前仅在 concatenated_gzip_streams 分支)。请参见 https://github.com/ymnk/jzlib/issues/12 了解更多详情

Workaround is to use GZIPInputStream from JZlib (currently only in concatenated_gzip_streams branch). See https://github.com/ymnk/jzlib/issues/12 for more details.

这篇关于从GZIPInputStream截断输出在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆