Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
my_rotine (Response.GetString ("UTF8"))
Response.Release
End Sub
The string that the server sent is about 30 to 40 bytes only and worked fine.
But now the string will be about 3 to 4 Kbytes.
My questions are :
1 - Is better to use GetAsynchronously like this :
B4X:
Sub hb_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Response.GetAsynchronously("Response", File.OpenOutput(File.DirInternalCache, "temp.txt", False), True, TaskId)
End Sub
Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
If Success Then
Dim in As InputStream
in = File.OpenInput(File.DirInternalCache, "temp.txt")
....
2 - Or use httputils like this :
B4X:
Sub JobDone (Job As String)
Dim s As String
If HttpUtils.IsSuccess(b4a) Then
s = HttpUtils.GetString(b4a)
End If
End Sub
This app will get data about each 2 seconds.
I am afraid of the use of file.OpenOutput will use too much the flash memory of the device and make it degraded with time ...
3 - Is there a way to use the internal RAM to store the received data ?
Sub Globals
Dim my_buffer As OutputStream
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
my_buffer.InitializeToBytesArray(5000) ' I expect less than 2000 bytes here
Response.GetAsynchronously("Response", my_buffer, True, TaskId)
End Sub
This works ... but how do I read this bytes later ?
Searching Google i did :
B4X:
Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
Dim another_buffer () As Byte
another_buffer = my_buffer.ToBytesArray
Log (BytesToString(another_buffer, 0, another_buffer.Length, "UTF8"))
Works ... but is there another way to do it without copy the buffer ?
Sorry about this things but I do not know java / streams ... :sign0013: