Hello,
I am trying to zip and unzip a byte array to another byte array. The first Sub throws an exception in zis.RunMethod("write",...) method and the second returns the same array length it reads. I cannot figure out as I am not completely java literate what is wrong... Can anyone help? Thanks...
I am trying to zip and unzip a byte array to another byte array. The first Sub throws an exception in zis.RunMethod("write",...) method and the second returns the same array length it reads. I cannot figure out as I am not completely java literate what is wrong... Can anyone help? Thanks...
B4X:
Public Sub ZipByteArray(ba() As Byte) As Byte()
Dim otp1 As OutputStream
otp1.InitializeToBytesArray(0)
Dim zis As JavaObject
zis.InitializeNewInstance("java.util.zip.ZipOutputStream", Array(otp1))
zis.RunMethod("write", Array(ba, 0, ba.Length))
Dim bRe() As Byte
bRe = otp1.ToBytesArray
Return bRe
End Sub
Public Sub UnzipByteArray(ba() As Byte) As Byte()
Dim inp1 As InputStream
inp1.InitializeFromBytesArray(ba, 0, ba.Length)
Log(inp1.BytesAvailable)
Dim zis As JavaObject
zis.InitializeNewInstance("java.util.zip.ZipInputStream", Array(inp1))
Dim inp2 As InputStream = zis
Return Bit.InputStreamToBytes(inp2)
' InputStream Is = new ByteArrayInputStream(ba);
' InputStream zis = new ZipInputStream(Is);
End Sub