iOS Question RandomAccessFile Send and Read Object Problem

tzfpg

Active Member
Licensed User
Longtime User
This is B4a "SendObject" coding
B4X:
Sub SendObject (Obj As Object)
  raf.WriteObject(Obj, True, 0)
  Dim size As Int = raf.CurrentPosition
  Dim data(size) As Byte
  raf.CurrentPosition = 0
  Do While raf.CurrentPosition < size
  raf.ReadBytes(data, raf.CurrentPosition, size - raf.CurrentPosition, _
  raf.CurrentPosition)
  Loop
  Dim j As HttpJob
  j.Initialize("send object", Me)
  j.PostBytes(link & "/Attendee_Location", data)
End Sub

and this is "ReadObject" coding

B4X:
Public Sub ReadObject (In As InputStream) As Object
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    File.Copy2(In, out)
    Dim raf2 As RandomAccessFile
    raf2.Initialize3(out.ToBytesArray, False)
    Dim res As Object = raf2.ReadObject(0)
    raf2.Close
    Return res
End Sub

How can i convert to B4i code. I try many times and no luck
Please help me.
 
Last edited:

tzfpg

Active Member
Licensed User
Longtime User
Thanks Erel,

I will try it out on Monday. If any problem, i will feedback at here

Thanks a lot.
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
B4X:
Sub SendObject (Obj As Object)
   raf.WriteB4XObject(Obj, True, 0)
   Dim size As Int = raf.CurrentPosition
   Dim data(size) As Byte
  raf.CurrentPosition = 0
   Do While raf.CurrentPosition < size
     raf.ReadBytes(data, raf.CurrentPosition, size - raf.CurrentPosition, _
       raf.CurrentPosition)
   Loop
 
   Dim j As HttpJob
   j.Initialize("send object", Me)
   j.PostBytes(link & "/Attendee_Location", data)
End Sub

I found an error "Too Many Parameter" at raf.WriteB4XObject(Obj, True, 0) ,
If i change to raf.WriteB4XObject(Obj, 0) then i got an error "CurrentPosition is Readonly" at raf.CurrentPosition = 0
Please help me, i stuck at here.
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
Hi Erel,

CurrentPosition already fixed. Another problem occur, when i debug the coding "Dim res As Object = raf2.ReadB4XObject(0)".
I get the following error message..
B4X:
Error occurred on line: 75 (main)
Error decompressing data
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  Staff Location       -[B4ICompressedStreams DecompressBytes::] + 532
  Staff Location       -[B4ISerializator ReadObject::] + 88
  Staff Location       -[B4IRandomAccessFile ReadB4XObject:] + 332
  Staff Location       -[b4i_main _readobject:] + 714
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 300
  Staff Location       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1936
Staff Location       -[B4IShell runMethod:] + 496
Staff Location       -[B4IShell raiseEventImpl:method:args::] + 1846
Staff Location       -[B4IShellBI raiseEvent:event:params:] + 1280
Staff Location       -[B4ICommon CallSub4::::] + 346
Staff Location       -[B4ICommon CallSub2::::] + 254
Staff Location       -[b4i_httpjob _complete::] + 414
Staff Location       -[b4i_httputils2service _completejob::::] + 752
Staff Location       -[b4i_httputils2service _hc_responsesuccess::] + 296
CoreFoundation       <redacted> + 68
CoreFoundation       <redacted> + 300
Staff Location       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1936
Staff Location       -[B4IShell runMethod:] + 496
Staff Location       -[B4IShell raiseEventImpl:method:args::] + 2060
Staff Location       -[B4IShellBI raiseEvent:event:params:] + 1280
Staff Location       __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 244
libdispatch.dylib    <redacted> + 372
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 718
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1512
CoreFoundation       CFRunLoopRunSpecific + 476
CoreFoundation       CFRunLoopRunInMode + 106
GraphicsServices     GSEventRunModal + 136
UIKit                UIApplicationMain + 1440
Staff Location       main + 116
libdyld.dylib        <redacted> + 2
)

Is it related to B4A "raf.WriteObject(Obj, true ,0)" and B4I "raf.WriteB4XObject(Obj, 0)"

Please look for me.... thanks
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
Erel, my android client app run well with b4j server app, now start to create ios client app.
Have any temporary solution for this case?
 
Upvote 0

tzfpg

Active Member
Licensed User
Longtime User
Hi Erel,

Got any serialization method to recommend... I totally no idea on how to do it.

I decide to rewrite program for B4J server and B4a client version to combine with IOS..
 
Upvote 0
Top