This is a continuation of this --> https://www.b4x.com/android/forum/t...e-file-cluelessness.145987/page-2#post-925674
I very much appreciate @drgottjr posting the B4a code. I have been attempting to duplicate it in my B4j Exporterator.
The B4a app appears to simply StringBuilder append the blocs of binary blobs fetched from the map buried in the Json string? However, when I try this I get "half" an image, and now with strange star-dots (attached).
The math regarding the "total size" and the "offset" does not work. The B4a app does not appear to care about either of these things.
I am missing something simple.
Here is a bunch of info...
I very much appreciate @drgottjr posting the B4a code. I have been attempting to duplicate it in my B4j Exporterator.
The B4a app appears to simply StringBuilder append the blocs of binary blobs fetched from the map buried in the Json string? However, when I try this I get "half" an image, and now with strange star-dots (attached).
The math regarding the "total size" and the "offset" does not work. The B4a app does not appear to care about either of these things.
I am missing something simple.
Here is a bunch of info...
B4X:
Waiting for debugger to connect...
Program started.
AppStart
SUB ProcessFile
SUB ParseRecord: inJson.Lenth = 87570
top level = **********************************************
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim Blob_Segment_No As String = root.Get("Blob_Segment_No")
Dim Blob_Image_ID As String = root.Get("Blob_Image_ID")
Dim Blob_Person_ID As String = root.Get("Blob_Person_ID")
Dim Blob_Total_Size As String = root.Get("Blob_Total_Size")
Dim Blob_Seg_Offset As String = root.Get("Blob_Seg_Offset")
Dim Blob_Format As String = root.Get("Blob_Format")
Dim Blob_Segment As Map = root.Get("Blob_Segment")
Dim $binary As String = Blob_Segment.Get("$binary")
Dim $type As String = Blob_Segment.Get("$type")
------------------------------------------------------------------
Blob_Segment_No = 0
Blob_Total_Size = 108533
Blob_Seg_Offset = 0
*** new image ***
binary from map length = 87384
NEW sb.Length = 87384
rCount = 1
------------------------------------------------------------------
Blob_Segment_No = 1
Blob_Total_Size = 108533
Blob_Seg_Offset = 65536
*** append to image ***
binary from map length = 57332
NEW sb.Length = 144716
rCount = 2
SaveImage: sb.Length = 144716
*** wrote bytes ***
B4X:
Private Sub ProcessFile
Log("SUB ProcessFile")
' show top-level json
Dim TR As TextReader
TR.Initialize(File.OpenInput(File.DirAssets,"myexport.json"))
Dim rLine As Object = TR.ReadLine
Dim result As String = LogB4jCode(rLine)
LogError("top level = **********************************************" & CRLF)
Log(result)
Do While rLine<> Null
LogError("------------------------------------------------------------------")
ProcessRecord(rLine)
rCount = rCount + 1
Log("rCount = " & rCount)
If rCount = 2 Then
SaveImage
Exit
End If
rLine = TR.ReadLine
Loop
End Sub
Private Sub ProcessRecord(inJson As String)
'Log("ProcessRecord: inJson.Length = " & inJson.Length)
Dim Parser As JSONParser
Parser.Initialize(inJson)
Dim jRoot As Map = Parser.NextObject
Dim Blob_Segment_No As String = jRoot.Get("Blob_Segment_No")
Log("Blob_Segment_No = " & Blob_Segment_No)
'Dim Blob_Image_ID As String = jRoot.Get("Blob_Image_ID")
'Log("Blob_Image_ID = " & Blob_Image_ID)
'Dim Blob_Person_ID As String = jRoot.Get("Blob_Person_ID")
'Log("Blob_Person_ID = " & Blob_Person_ID)
Dim Blob_Total_Size As String = jRoot.Get("Blob_Total_Size")
Log("Blob_Total_Size = " & Blob_Total_Size)
Dim Blob_Seg_Offset As String = jRoot.Get("Blob_Seg_Offset")
Log("Blob_Seg_Offset = " & Blob_Seg_Offset)
'Dim Blob_Format As String = jRoot.Get("Blob_Format")
'Log("Blob_Format = " & Blob_Format)
Dim Blob_Segment As Map = jRoot.Get("Blob_Segment")
'Log("Blob_Segment.Size = " & Blob_Segment.Size)
''Dim binary As String = Blob_Segment.Get("$binary")
'Log("binary 30 = " & binary.SubString2(0, 30))
'Dim jType As String = Blob_Segment.Get("$type")
'Log("jType = " & jType)
If Blob_Segment_No = 0 Then
LogColor("*** new image ***", 0xFFD8FF00 )
If sb.IsInitialized Then
SaveImage
End If
sb.Initialize
sb.Append(GetBinaryData(Blob_Segment))
Else
LogColor("*** append to image ***", 0xFFD8FF00)
Dim str As String = GetBinaryData(Blob_Segment)
sb.Append(str)
End If
Log("NEW sb.Length = " & sb.Length)
End Sub
Private Sub SaveImage
Log("SaveImage: sb.Length = " & sb.Length)
If sb.Length = 0 Then
LogError("zero length imgstr")
Return
End If
' write out new image
Dim su As StringUtils
Dim by() As Byte
by = su.DecodeBase64(sb.ToString)
File.WriteBytes(DIR,"test.jpeg", by)
LogColor("*** wrote bytes ***", 0xFFFF00AA)
End Sub
Private Sub GetBinaryData(inMap As Map) As String
'Log("SUB GetBinaryData: inMap.Size = " & inMap.size)
Dim rStr As String
rStr = inMap.Get("$binary")
Log("binary from map length = " & rStr.Length)
Return rStr
End Sub