Dim lines As List = File.ReadList(...)
Dim s As String = File.ReadString(...)
This data file contains bytes 0-255 in value
for plain data files you need to use the randomaccess library and readbytes().
If j.Success Then
Log(j.GetString)
End If
If j.Success Then
Log(j.ReadBytes)
End If
my reply above is focussed on data being real bytes.
Does the quote above mean this? or is it stored as 240,13,167 text? then you can use file.readstring aswell.
Sub ToUnsigned(b As Byte) As Int
Return Bit.And(0xFF, b)
End Sub
bytes in b4a are signed.
you can convert it to unsigned (0-255) with
B4X:Sub ToUnsigned(b As Byte) As Int Return Bit.And(0xFF, b) End Sub
Sub Download (Callback As Object, link As String) As HttpJob
Dim j As HttpJob
j.Initialize("", Callback)
j.Download("http://mydomain.com/123.ABC")
Return j
End Sub
Sub Button_Download_Click
Wait For (Download(Me, "http://mydomain.com/123.ABC")) JobDone (j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
j.Release
End Sub
Sub Button_Firmware_Click
Dim job As HttpJob
job.Initialize("j", Me)
job.Download("http://mydomain.com/123.abc")
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
Log(job.GetString)
For A1 = 0 To job.GetString.Length
' Need to load the array here
Next
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub
Sub ToUnsigned(b As Byte) As Int
Return Bit.And(0xFF, b)
End Sub
The text from job.getstring is a STRING. There is no array.Need to load the array here
Sub Process_Globals
Private fx As JFX
Dim bytes(10000) As Byte
End Sub
Sub AppStart (Form1 As Form, Args() As String)
Dim job As HttpJob
job.Initialize("j", Me)
job.Download("http://server-sql/123.abc")
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
job.GetInputStream.ReadBytes(bytes,0,job.GetInputStream.BytesAvailable)
For x=0 To 10'job.GetInputStream.BytesAvailable-1
Log( Bit.And(bytes(x),255) )
Next
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
Log(job.GetString)
Dim S As String
s = job.GetString
Dim bytes() As Byte = s.GetBytes("UTF8")
For A1 = 0 To job.GetString.Length - 1
Log(bytes(A1))
Next
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub
good news... you can access the stream data at once.
this is in B4J
B4X:Sub Process_Globals Private fx As JFX Dim bytes(10000) As Byte End Sub Sub AppStart (Form1 As Form, Args() As String) Dim job As HttpJob job.Initialize("j", Me) job.Download("http://server-sql/123.abc") End Sub Sub JobDone(job As HttpJob) If job.Success Then job.GetInputStream.ReadBytes(bytes,0,job.GetInputStream.BytesAvailable) For x=0 To 10'job.GetInputStream.BytesAvailable-1 Log( Bit.And(bytes(x),255) ) Next Else Log("Error: " & job.ErrorMessage) End If job.Release End Sub
if this send -127 - 127 values to the log then you need to use ToUnsigned on the byte.bytes(A1)
Log(ToUnsigned(bytes(A1)))
job.GetInputStream.ReadBytes(bytes,0,job.GetInputStream.BytesAvailable)
For x = 0 To job.GetInputStream.BytesAvailable - 1
Log( Bit.And(bytes(x),255))
Log(ToUnsigned(bytes(x)))
Next
Log(job.GetString)
job.GetInputStream.ReadBytes(bytes,0,job.GetInputStream.BytesAvailable)
For x = 0 To job.GetInputStream.BytesAvailable - 1
'Log( Bit.And(bytes(x),255))
'Log(ToUnsigned(bytes(x)))
Log(bytes(x))
Next
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?