Android Question Random Access file data

RickV

Member
Licensed User
I need some assistance in making the following code work as a random access random record size read and write chunck or fixed width read and write if you will.

Spent a couple of hours reading many posts in the forum, with many coffees LOL, but not sure why I am getting a syntax error on the if and end end if statements.......... any ideas ?


Basically I am writing a zmodem crash recovery protocol to transfer image file data over a tcp-ip socket. Cannot use ftp must be done with this type of implementation as b4x data packets arrive out of sequence in the astreams new data event. (widely documented)

If anyone can see issues, please let me know the correct way.
Thanks

B4X:
    Dim aaa As String
    Dim RAF As RandomAccessFile
    Dim b() As Byte
    Dim x() As Byte
            
    TXRec = Rec ' record number
    RAF.Initialize(File.DirInternalCache, fName, True)
    RAF.CurrentPosition = Rec
    If RAF.Size - (RAF.CurrentPosition + 4096) => 4096 Then '   <------ this line throws syntax error in logs window
            x = RAF.ReadBytes(b, 0, 4096, TXRec)
            TXRec = TXRec + 4096
            aaa = BytesToString(x, 0, x.Length, CharSet)
            SendIt(18550, Pad(fName,20,0) & aaa) 'this handles the encryption, checksums etc and sends the data
        End If  '   <------ this line throws syntax error in logs window

        If RAF.Size - (RAF.CurrentPosition + 2048) => 2048 Then
            x = RAF.ReadBytes(b, 0, 2048, TXRec)
            TXRec = TXRec + 2048
            aaa = BytesToString(x,0,x.Length,CharSet)
            SendIt(18550, Pad(fName,20,0) & aaa)
        End If
'        '''''''  
'        '''''''  
        If RAF.Size - (RAF.CurrentPosition + 1) => 1 Then
            x = RAF.ReadBytes(b, 0, 1, TXRec)
            TXRec = TXRec + 1
            aaa = BytesToString(x,0,x.Length,CharSet)
            SendIt(18550, Pad(fName,20,0) & aaa)
        End If
        If RAF.Size - (RAF.CurrentPosition + 1) > RAF.Size  Then
            SendIt(18551, Pad(fName,20,0))
        End If
    'End If
    RAF.Close
 

teddybear

Well-Known Member
Licensed User
1.What the b4x equivalent to SEEK ?
In B4X, the Seek is CurrentPosition of the raf(randomaccessfile), you can do same thing like VB6.
raf.ReadBytes(Chunk1,0,4096,raf.CurrentPosition) 'CurrentPosition += 4096
raf.ReadBytes(Chunk2,0,2048,raf.CurrentPosition)
2.How do I move the current position within the file to byte x ?
raf.CurrentPosition=x
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
So your looking for something like this from Library documentation: RandomAccessFile - v2.32:
 
Upvote 0

RickV

Member
Licensed User
Thanks everyone, I will go have a look-see at this later tonight. I have a few pages to build first.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…