Maybe I am missing something basic here, but I havent been able to figure it out.
I am writing out a map, which contains a custom type in the value, while the key is a string. I coudlnt use ReadMap/WriteMap so I had to use Random Access File's ReadObject/WriteObject.
This is my code:
I tried writing the whole map at once using WriteObject but I was getting the same errors so I tried breaking it down to string but still same issue.
Reading back:
The exception I get is:
I have used RAF with Lists/Custom types but this is the first time I needed to use them with maps. I must be doing something wrong but cant figure it out!
I am writing out a map, which contains a custom type in the value, while the key is a string. I coudlnt use ReadMap/WriteMap so I had to use Random Access File's ReadObject/WriteObject.
This is my code:
B4X:
Type DownloadTableType ( _
iFile As String, _
remote_lm As String, _
local_lm As String)
I tried writing the whole map at once using WriteObject but I was getting the same errors so I tried breaking it down to string but still same issue.
B4X:
Sub GenerateDownloadTable(pipename As String, new_map As Map, ct As CurrentTaskType) As Map
Dim p As PipeType
p = GetPipe(pipename)
Dim writemap As Map
writemap.Initialize
For i = 0 To new_map.Size -1
'Update LocalMod time
Dim DTEntry As DownloadTableType
DTEntry = new_map.GetValueAt(i)
DTEntry.local_lm = GetLocalFileDate(DTEntry.iFile ,p)
'Remove failed downloads
If GetCTResult(DTEntry.iFile, ct) = 0 Then
writemap.Put(DTEntry.iFile,DTEntry)
End If
Next
Log("Download Sync Table")
LogSyncMap(writemap)
Dim RAF As RandomAccessFile
RAF.Initialize(File.DirInternal,p.Name & "_sync.txt",False)
For i = 0 To writemap.Size-1
Dim DTEntry As DownloadTableType
DTEntry = writemap.Get(i)
RAF.WriteObject(DTEntry.iFile ,False,RAF.CurrentPosition)
RAF.WriteObject(DTEntry.local_lm ,False,RAF.CurrentPosition)
RAF.WriteObject(DTEntry.remote_lm ,False,RAF.CurrentPosition)
Next
RAF.Close
End Sub
Reading back:
B4X:
Sub LoadDownloadSyncTable(pipename As String) As Map
Dim p As PipeType
p = GetPipe(pipename)
Dim retmap As Map
retmap.Initialize
If File.Exists(File.DirInternal, p.Name & "_sync.txt") Then
Dim RAF As RandomAccessFile
RAF.Initialize(File.DirInternal,p.Name & "_sync.txt",True)
If RAF.Size <> 0 Then
Do While RAF.CurrentPosition < RAF.Size
Dim s,s1,s2 As String
s = RAF.ReadObject(RAF.CurrentPosition )
s1 = RAF.ReadObject(RAF.CurrentPosition )
s2 = RAF.ReadObject(RAF.CurrentPosition )
Dim DTE As DownloadTableType
DTE.iFile = s
DTE.local_lm = s1
DTE.remote_lm = s2
retmap.Put(s,DTE)
Loop
End If
RAF.Close
End If
dl_sync_table = retmap
LogSyncMap(dl_sync_table)
Return retmap
End Sub
The exception I get is:
B4X:
synchelper_loaddownloadsynctable (B4A line: 933)
s = RAF.ReadObject(RAF.CurrentPosition )
java.lang.OutOfMemoryError
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readHelper(RandomAccessFile.java:362)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadObject(RandomAccessFile.java:354)
at com.maximussoft.cloudpipes.synchelper._loaddownloadsynctable(synchelper.java:512)
at com.maximussoft.cloudpipes.dpservice._processnexttask(dpservice.java:2034)
at com.maximussoft.cloudpipes.dpservice._response_streamfinish(dpservice.java:2619)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA$2.run(BA.java:244)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4575)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Pause, UserClosed = true **
I have used RAF with Lists/Custom types but this is the first time I needed to use them with maps. I must be doing something wrong but cant figure it out!