1 - From a webservice. NET 2008 (vb), I have a method that returns an array of bytes, the byte array is actually a string "Hola Mundo" ("Hello World" in English) compressed with the Class of System.IO.Compression GZipStream.
2 - The method returns the string "Hola Mundo" compressed, and this is what the webservice returns:
<base64Binary>
H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ir5dlVn6xXo5q/4f0m5DIgoAAAA=
</base64Binary>
3 - if I do a test from a windows application from Visual Basic. NET to run this method returns me this string and Unzip with another function I have, it brings me the "Hola Mundo" ....
4 - On Android (Eclipse) and I managed to make the request and bring me the previous string ... but do not know how to decompress and show me "Hola Mundo" ...
5 - I have tried several codes from the web, but none work.
anyone know anything about this? thank you very much from now.
Greetings.
If Android supports java.util.zip.GZIPInputStream, that's what you want.
For example:
byte[] bytes = getBytesFromWebService();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
GZIPInputStream gzip = new GZIPInputStream(bais);
try {
InputStreamReader reader = new InputStreamReader(gzip, "UTF-8");
try {
String firstLine = new BufferedReader(reader).readLine();
...
} finally {
reader.close();
}
} finally {
gzip.close();
}
I can't comment on Android, but you just need to:
In C#, this would be something like:
string base64 = "H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ir5dlVn6xXo5q/4f0m5DIgoAAAA=";
byte[] blob = Convert.FromBase64String(base64);
string orig;
using (var ms = new MemoryStream(blob))
using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
using (var reader = new StreamReader(gzip))
{
orig = reader.ReadToEnd(); // Hola Mundo
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With