Hi,
I'm using GZip to compress some XML in a SOAP webservice and push down to an Android app. I can get the data to work from a VB app but cannot get it to work when decoding in Android. Code is below. In the VB code it seems that you need to include the length of the orginal byte array of the string, is that needed in Android? I've tried with and without it and no luck
The error that I seem to get is about a magic number not existing...
WebService code:
Android code (code triggers as expected then fails on marked line)
Thanks for any help
Jon
I'm using GZip to compress some XML in a SOAP webservice and push down to an Android app. I can get the data to work from a VB app but cannot get it to work when decoding in Android. Code is below. In the VB code it seems that you need to include the length of the orginal byte array of the string, is that needed in Android? I've tried with and without it and no luck
The error that I seem to get is about a magic number not existing...
WebService code:
B4X:
<WebMethod(Description:="Get various data tables - down only")> _
Public Function GetGZippedDataTEST() As String
Dim _encodedString As Byte() = Encoding.UTF8.GetBytes("Test text")
Dim _memoryStream As MemoryStream = New MemoryStream()
Dim _gZipStream As GZipStream = New GZipStream(_memoryStream, CompressionMode.Compress, True)
_gZipStream.Write(_encodedString, 0, _encodedString.Length)
_memoryStream.Position = 0
Dim _compressedData As Byte() = New Byte(_memoryStream.Length - 1) {}
' Fill the compressed data byte array
_memoryStream.Read(_compressedData, 0, _compressedData.Length)
' Add the length of the original byte array to the start of the output byte array
Dim _amendedByteArray As Byte() = New Byte(_compressedData.Length + 3) {}
System.Buffer.BlockCopy(_compressedData, 0, _amendedByteArray, 4, _compressedData.Length)
System.Buffer.BlockCopy(BitConverter.GetBytes(_encodedString.Length), 0, _amendedByteArray, 0, 4)
Return Convert.ToBase64String(_amendedByteArray)
End Function
Android code (code triggers as expected then fails on marked line)
B4X:
Sub ReactiveDataParser_EndElement (uri As String, name As String, text As StringBuilder)
If name = "string" Then
Dim objStringUtils As StringUtils
Dim objInputByteArray() As Byte
objInputByteArray = objStringUtils.DecodeBase64(text)
Dim objInputStream As InputStream
'objInputStream.InitializeFromBytesArray(objInputByteArray, 0, objInputByteArray.Length)
objInputStream.InitializeFromBytesArray(objInputByteArray, 4, objInputByteArray.Length-4)
Dim objCompressedStreams As CompressedStreams
Dim objDecompressedByteArray() As Byte
' Code fails on next line
objDecompressedByteArray = objCompressedStreams.DecompressBytes(objInputByteArray ,"gzip")
Dim objCompressedString As String
objCompressedString= BytesToString(objDecompressedByteArray,0, objDecompressedByteArray.Length, "UTF8")
End If
End Sub
Thanks for any help
Jon