GZIPInputStream失败,IOException的是Android 2.3,但在所有的previous发行工作正常? [英] GZIPInputStream fails with IOException in Android 2.3, but works fine in all previous releases?

查看:233
本文介绍了GZIPInputStream失败,IOException的是Android 2.3,但在所有的previous发行工作正常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了我的今天(2.3.2)手机姜饼和发射了一个应用程序,我公司开发并认为这无法加载其数据。该应用程序运行得很好,我已经测试了从1.6到2.2所有其他版本的Andr​​oid,但随后一个IOException姜饼。有谁知道,如果事情在任何GZipInputStream或URL.openStream()?改变

I updated my phone to Gingerbread today (2.3.2) and fired up an app I developed and saw that it failed to load its data. The app runs fine on every other version of Android I have tested from 1.6 to 2.2, but then an IOException in Gingerbread. Does anybody know if something changed in either GZipInputStream or URL.openStream()?

有问题的code是类似以下内容:

The problematic code is similar to the following:

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;
}

在1.6到2.2,这code正常工作,在2.3中,我得到一个IOException,使用一个关于魔块是不正确的消息。我假设的东西已经与OpenStream的是搞乱了MIME类型或某事在这个数据变化。我读等地发现的OpenStream不是最可靠的方法来处理HTTP连接,所以这可能是一个很好的借口,返工我的连接code。

In 1.6 to 2.2, this code works fine, in 2.3 I get an IOException with a message about the magic block being incorrect. I'm assuming something has changed with openStream that is messing up the MIME-type or something on this data. I read other places that openStream is not the most reliable way to handle HTTP connections, so this might be a good excuse to rework my connections code.

推荐答案

我遇到了同样的问题在这里。它看起来像姜饼(2.3)改变gzip压缩的数据流的处理方式。看着魔块的字符表示的OpenStream()自动检测GZip压缩的数据,并通过正确的流去codeR运行它。当然,如果你试图运行在相同的流另一GZIP德codeR,将抛出IOException失败。

I'm running into the same issue here. It looks like Gingerbread (2.3) changed the way GZipped streams are handled. Looking at the "magic block" characters indicates that openStream() automatically detects GZipped data and runs it through the correct stream decoder. Of course, if you attempt to run another GZIP decoder on the same stream, that will fail with an IOException.

有一对夫妇的方式来处理这个问题。第一种方式是切换到的HttpClient / HTTPGET。但也不能保证,这也不会在将来改变。基本上,这是一个黑客得到它的再次合作。一个更完整的解决方案可能是这样:

There are a couple ways to handle this. The first way is to switch to HttpClient/HttpGet. BUT there is no guarantee that this also won't change in the future. Basically, that is a hack to get it working again. A more complete solution might be to do:

InputStream in = url.openStream();
GZIPInputStream zin;
try {
    zin = (GZIPInputStream)in;
} catch (Exception e) {
    zin = new GZIPInputStream(in);
}

对于老版本的Andr​​oid,试图投的异常火灾,在新版本的Andr​​oid,转换成功。滥用异常处理这种方式是不是pretty的,但它的工作原理。

For older versions of Android, an exception fires while attempting the cast and, on newer versions of Android, the cast succeeds. Abusing an exception handler this way is not pretty but it works.

这,当然,将是为com pressed或者看起来是GZIP COM pressed数据的二进制数据为基础数据的一个问题。 Android的开发者认为这种变化是不是一个错误:

This, of course, will be a problem for underlying data that is compressed or binary data that looks like it is GZIP compressed data. The Android devs think this change isn't a bug:

HTTP://$c$c.google。 COM / P /安卓/问题/详细信息?ID = 16227

我不同意。这是严重破损。

I disagree. This is severe breakage.

这篇关于GZIPInputStream失败,IOException的是Android 2.3,但在所有的previous发行工作正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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