Here is a code that fails in the second loop:
It fails with this error (line 306 is the line indicated as highlighed above):
Code that fails in second loop:
Dim ins As InputStream
ins = File.OpenInput(FileFolder, FileName)
Dim iCount As Int = 0
Dim lngBytesAv As Long = ins.BytesAvailable
Log ("Bytes Available:" & lngBytesAv)
Dim iBLen As Int = 512
Do While lngBytesAv >= iCount
Log(lngBytesAv)
Log(iCount)
If lngBytesAv - iCount < 512 Then
iBLen = lngBytesAv - iCount
If iBLen = 0 Then
Exit
End If
End If
Log(iBLen)
Dim bToSend(iBLen) As Byte
ins.ReadBytes(bToSend, iCount, bToSend.Length)
iCount = iCount + iBLen
ProcessByteArray(bToSend)
Loop
It fails with this error (line 306 is the line indicated as highlighed above):
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Folder: /storage/emulated/0/Android/data/b4a.example/files/Videos
File Name: trial.mp4
Bytes Available:7830408
7830408
0
512
7830408
512
512
Error occurred on line: 316 (FileLoader)
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(BufferedInputStream.java:340)
at anywheresoftware.b4a.objects.streams.File$InputStreamWrapper.ReadBytes(File.java:484)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.fileloader._readfile(fileloader.java:438)
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Folder: /storage/emulated/0/Android/data/b4a.example/files/Videos
File Name: trial.mp4
Bytes Available:7830408
7830408
0
512
7830408
512
512
Error occurred on line: 316 (FileLoader)
java.lang.IndexOutOfBoundsException
at java.io.BufferedInputStream.read(BufferedInputStream.java:340)
at anywheresoftware.b4a.objects.streams.File$InputStreamWrapper.ReadBytes(File.java:484)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.fileloader._readfile(fileloader.java:438)
Last edited: