Hi all,
I have two arrays of bytes and I'd like to append one after the other resulting in a third array containing all the data from the source ones.
So far I coded like this:
WriteBytes causes error OutOfBounds (lenght:992 - index:992).
It looks like raf is fixed at its first length, so whenever a byte goes to position 992 it gets mad.
My question: what's wrong with the above code and, eventually, how can I append an array to an existing one?
TIA
I have two arrays of bytes and I'd like to append one after the other resulting in a third array containing all the data from the source ones.
So far I coded like this:
B4X:
'first array comes from a string builder object
Dim data1() As Byte = sb.ToString.GetBytes("UTF8")
Log("data1 size: "&data1.Length) '992 bytes. OK
Dim raf As RandomAccessFile
raf.Initialize3(data1,False)
raf.CurrentPosition = raf.Size 'set to 992, the first "free" slot
'second array comes from a file
Dim InS As InputStream
InS = File.OpenInput(File.DirAssets,"myfile.png")
Dim data2() As Byte
data2=Bit.InputStreamToBytes(InS)
Log("data2 size: "&data2.Length) '13607 bytes. OK
Dim i As Int
i=raf.WriteBytes(data2,0,data2.Length,raf.CurrentPosition) 'ERROR out of bounds on 992!
WriteBytes causes error OutOfBounds (lenght:992 - index:992).
It looks like raf is fixed at its first length, so whenever a byte goes to position 992 it gets mad.
My question: what's wrong with the above code and, eventually, how can I append an array to an existing one?
TIA