草庐IT

Android:读取 ASSETS 文件夹中的 GZIP 文件

如何在Android中读取位于“ASSETS”(或resources/raw)文件夹中的GZIP文件?我试过下面的代码,但我的流大小总是1。GZIPInputStreamfIn=newGZIPInputStream(mContext.getResources().openRawResource(R.raw.myfilegz));intsize=fIn.available();出于某种原因,大小始终为1。但如果我不对文件进行GZIP,它工作正常。注意:使用Android1.5 最佳答案 我在从assets文件夹中读取gz文件时遇到了同

android - GZIPInputStream 抛出未知格式(魔数(Magic Number) 213c)

当我使用GZIPInputStream压缩从Internet获取的字节时,程序运行错误如下:05-0817:37:02.465:W/System.err(744):java.io.IOException:unknownformat(magicnumber213c)05-0817:37:02.465:W/System.err(744):atjava.util.zip.GZIPInputStream.(GZIPInputStream.java:84)05-0817:37:02.465:W/System.err(744):atjava.util.zip.GZIPInputStream.(GZ

android - GZIPInputStream 在 Android 2.3 中因 IOException 而失败,但在所有以前的版本中工作正常?

我今天将手机更新到Gingerbread(2.3.2)并启动了我开发的应用程序,但发现它无法加载数据。该应用程序在我从1.6到2.2测试过的所有其他Android版本上运行良好,但随后在Gingerbread中出现IOException。有人知道GZipInputStream或URL.openStream()中是否发生了变化吗?有问题的代码类似于以下内容:InputStreamin=null;GZIPInputStreamzin=null;URLurl=null;try{url=newURL("http://www.test.com/gzipped_data.gz");in=url.o

android - 为什么 GZip 算法的结果在 Android 和 .Net 中不一样?

为什么GZip算法在Android和.Net中的结果不一样?我在android中的代码:publicstaticStringcompressString(Stringstr){Stringstr1=null;ByteArrayOutputStreambos=null;try{bos=newByteArrayOutputStream();BufferedOutputStreamdest=null;byteb[]=str.getBytes();GZIPOutputStreamgz=newGZIPOutputStream(bos,b.length);gz.write(b,0,b.length

java - 如何通过改造获得 gzip 压缩的 xml 文件?

我正在使用改造从网络获取数据。现在我的问题是我必须得到一个gzip文件,而改造需要某种我不知道如何正确实现的标题,显然。我对此进行了研究,但似乎没有任何帮助,因为大多数开发人员都在使用json。这是我正在尝试做的事情:Retrofitretrofit=newRetrofit.Builder().baseUrl("thisismybaseurl").addConverterFactory(SimpleXmlConverterFactory.create()).build();和我的界面:publicinterfaceRestAPI{@GET("main_data1.gz")Callget

java - 谷歌云端点 EOFException

我在AppEngine中有以下方法:@ApiMethod(name="authed",path="greeting/authed")publicHelloGreetingauthedGreeting(Useruser){...}我在AndroidAsyncTask中的doInBackground方法:HelloGreetinghg=null;try{hg=service.authed().execute();}catch(IOExceptione){Log.d("error",e.getMessage(),e);}returnhg;我遇到了ff错误:/_ah/api/.../v1/gr

android - HttpURLConnection 不解压缩 Gzip

我正在尝试在Gingerbread+Android设备上使用HttpURLConnection,但遇到了gzip编码问题。根据文档"InGingerbread,weaddedtransparentresponsecompression.HttpURLConnectionwillautomaticallyaddthisheadertooutgoingrequests,andhandlethecorrespondingresponse:Accept-Encoding:gzip"问题是这实际上并没有发生。Accept-Encoding:gzipheader根本没有被添加。如果我手动添加它,我

android - 为什么 Android aapt 去掉 assets 的 .gz 文件扩展名?

当我将GZIP压缩文件添加到我的Android项目的Assets时,“.gz”扩展名在项目打包时被删除。(因此,例如,我的Assets文件夹中的“foo.gz”需要使用getAssets().open("foo")在代码中访问。)这似乎不会发生在其他我正在使用的扩展名(例如“.html”)。Assets仍然是GZIP压缩的(我必须将输入流包装在GZIPInputStream中才能读取它)。这是标准行为还是错误?如果它是标准的,是否有关于哪些扩展被剥离和哪些被保留的文档?编辑:我看错了事情。我在使用Eclipse插件时遇到了这个问题。我没有尝试直接运行aapt来查看问题是出在工具本身还是

java - 如何向压缩的 HttpUrlConnection 写入 post 语句?

我一直被告知您应该压缩数据以提高效率。在inputsize上,这个比较容易,如下图:HttpURLConnectionurlConnection=(HttpURLConnection)newURL(url).openConnection();urlConnection.setRequestProperty("Accept-Encoding","gzip");InputStreaminstream=urlConnection.getInputStream();Map>headers=urlConnection.getHeaderFields();ListcontentEncodings=

android - 在 Android 中自动处理 gzip http 响应

引用:http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d4e1261此页面说明以下代码将设置HttpClient以自动处理gzip响应(对HttpClient的用户透明):DefaultHttpClienthttpclient=newDefaultHttpClient();httpclient.addRequestInterceptor(newRequestAcceptEncoding());httpclient.addResponseInterceptor(newResponseCo