You can use OutputSteram.InitializeToBytesArray to create a memory stream. You should then write the text map with a TextWriter. OutputStream.ToBytesArray will return the array of bytes.
I'm not sure if I fully understand what you mean, but, based on your answers I have made the following code:
B4X:
Dim settings As Map
'**************************
some code to fill values in settings
'**************************
Dim bytesbuffer(100000) As Byte
Dim raf As RandomAccessFile
raf.Initialize3(bytesbuffer,True)
raf.WriteObject(settings,True,0)
Dim bc As ByteConverter
Dim HexString As String = bc.HexFromBytes(bytesbuffer)
stream.Write(HexString.SubString2(0,raf.CurrentPosition*2) & Chr(13) & Chr(10))
I convert the bytesbuffer to HexString because the stream is an AsyncStreamsText
The code seams to work as intended. My only concern is that the bytesbuffer must be
of fixed size. I do not want to oversize the buffer and the size of the written object could vary a lot. Is there a way around the buffer size concern?