Android Question How parse a Stored inputStream?

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
How parse a Stored inputStream?

Globals:

Dim XMLTopics as inputStream

I have a sub:

Sub ParseTopics (parsePar as InputStream)

Parser.parse (ParserPar, "MyParser")

If XMLtopics.IsInitialized = False Then
XMLtopics = parsePar
end If

end Sub


If parsePar is the result of a jobdone it works:

ParseTopics (Job.GetInputStream) ---> Ok.

But if at another time I try:

ParseTopics (XMLtopics) ---> It don´t works.

Error: java.io.IOException: BufferedInputStream is closed

Thank you for your help.
 

Ohanian

Active Member
Licensed User
Longtime User
Hi,

try this :

B4X:
    Dim Parser As JSONParser
    Dim ParserPar As InputStream
   
    ParserPar = File.OpenInput(File.DirAssets, "file.name")
    Parser.parse (ParserPar, "MyParser")
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Sorry about my English.

I have a global variable:

Dim XMLtopics as InputStream

I get parsePar as the result of a jobdone
( Job.GetInputStream)

Sub ParseTopics (parsePar as InputStream)

Log (XMLtopics.IsInitialized) --> return false

XMLtopics = parsePar

parser.parse (XMLtopics, "Parser3")
-->works

Log (XMLtopics.IsInitialized)
--> return true

Parser. Parse (XMLtopics, "Parser3") --> error

Error:
java.io.IOException: BufferedInputStream is closed
at java.io.BufferedInputStream.streamClosed(BufferedInputStream.java:118)

end Sub

Why I can not reuse XMLTopics? (in this sub and others subs)

Thank you.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why I can not reuse XMLTopics?
Because the data was already read from the input stream. Once it is read it is no longer available.

If you want to read it multiple times:
B4X:
Dim data() As Byte = Bit.InputStreamToBytes(parsePar)

'You can now create an InputStream that reads from data:
Dim in As InputStream
in.InitializeFromBytesArray (data, 0, data.Length)
 
Upvote 0
Top