小编Jus*_*per的帖子

GZIPInputStream在Android 2.3中因IOException失败,但在以前的所有版本中都能正常工作吗?

我今天将手机更新为Gingerbread(2.3.2)并启动了我开发的应用程序并发现它无法加载其数据.该应用程序在我从1.6到2.2测试的每个其他Android版本上运行正常,但随后在Gingerbread中出现了IOException.有人知道GZipInputStream或URL.openStream()中是否有变化吗?

有问题的代码类似于以下内容:

InputStream in = null;
GZIPInputStream zin = null;
URL url = null;
try {
    url = new URL("http://www.test.com/gzipped_data.gz");
    in = url.openStream();
    zin = new GZIPInputStream(in);
}
catch (MalformedURLException e) { 
    return false;
} 
catch (IOException e) {
    return false;
}
Run Code Online (Sandbox Code Playgroud)

在1.6到2.2中,这段代码运行正常,在2.3中我得到一个IOException,其中包含有关魔术块不正确的消息.我假设openStream发生了一些变化,搞乱了MIME类型或者这个数据上的东西.我读了其他地方,openStream不是处理HTTP连接最可靠的方法,所以这可能是重写我的连接代码的一个很好的借口.

android gzip gzipinputstream

5
推荐指数
1
解决办法
1561
查看次数

标签 统计

android ×1

gzip ×1

gzipinputstream ×1