Compressed Java Byte Array from .NET Webservice

1 - from the .NET 2008 web service (vb), I have a method that returns an array of bytes, the byte array is actually the string "Hola Mundo" ("Hello World" in English), compressed by the System.IO class .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, it returns me this line and Unzip with another function that I have, it brings me "Hola Mundo" ....

4 - on Android (Eclipse), and I managed to make a request and bring me the previous line ... but I don’t know how to unzip and show me "Hola Mundo" ...

5 - I tried several codes from the Internet, but nobody works.

Does anyone know about this? thank you very much.

Hey.

+3
source share
4 answers

If Android supports java.util.zip.GZIPInputStream, this is what you want.

For instance:

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();
}
+3
source

I can not comment on Android, but you just need to:

  • cancel base-64
  • cancel gzip
  • decode a string (presumably as UTF8)

In C #, it will be something like this:

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
}
+1
source

Android base-64. , Bouncy Castle. Bouncy Castle

ksoap2-android.

+1

Eli, ksoap2-android byte [] org.kobjects.base64.Base64.decode(String arg0)

: http://code.google.com/p/ksoap2-android/wiki/HowToUse?tm=2

+1

Source: https://habr.com/ru/post/1776675/


All Articles