Android Question read and decode a large file

coddy

Member
this is my sub that i think takes time to read and decode the file and makes me problems
readEncFile:
Sub readEncFile(dirName As String,fileName As String) As String
    Dim data() As Byte
    Dim Dokumentdatei As RandomAccessFile
    Dokumentdatei.Initialize(dirName,fileName,False)
    data=Dokumentdatei.ReadB4XObject(0)
    Dokumentdatei.Close
    data=encr.Decrypt(data,"something")
    return bc.StringFromBytes(data,"utf8")
End Sub
when the file is small it works well but with one of files which is 7kb it won't
i want to wait for this sub to be complete so i used (wait for) this way
something:
Sub getText As ResumableSub
    Dim temp As String
    wait for (readEncFile(File.DirDefaultExternal,"rest.pol")) complete (temp As String)
    Return temp
End Sub

i'm confused how to use wait for with this. readEncFile sub returns a string. how can i wait for sub to read and decode whole file
 

Midimaster

Active Member
Licensed User
How did you build the file? Perhaps the de-codings does not match the en-coding? Can you show us the corresponding saving-sub?

And what do you mean with "does not work..."? Problems with the text at the end or an error message during the SUB or a hang-up of the device?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Remember: code with File.DirDefaultExternal = broken code.

You cannot use Wait For with blocking methods. I guess that the slow part is the decryption. The serialization can be done asynchronously with B4XSerializator.

You can split the decryption part, though 7kb is quite small so I'm not sure that it is worth the added complexity: https://www.b4x.com/android/forum/t...-encryption-and-decryption.114141/post-713166
 
Upvote 0

coddy

Member
Remember: code with File.DirDefaultExternal = broken code.

You cannot use Wait For with blocking methods. I guess that the slow part is the decryption. The serialization can be done asynchronously with B4XSerializator.

You can split the decryption part, though 7kb is quite small so I'm not sure that it is worth the added complexity: https://www.b4x.com/android/forum/t...-encryption-and-decryption.114141/post-713166
yes the slow part is decryption.on my phone it takes almost 5 seconds and it's too long for me so i decided to decrypt the file already to be ready in memory until when i need it
 
Upvote 0
Top