B4J Question java.io.IOException: Stream closed

JackKirk

Well-Known Member
Licensed User
Longtime User
I create an input stream via a http job:

Payload_inputstream = Job.GetInputStream

when I copy it to an outputstream via:

File.Copy2(wrk_AWS_S3_B4A.Payload_inputstream, wrk_out)

I get the following:
If I trap it with:

Try
File.Copy2(wrk_AWS_S3_B4A.Payload_inputstream, wrk_out)
Catch
Log(LastException)
End Try

the copy actually works.

Any suggestions as to what I could do to prevent the error would be appreciated.
 

JackKirk

Well-Known Member
Licensed User
Longtime User
Oops,

I just worked out that this is happening because I do an earlier:

File.Copy2(wrk_AWS_S3_B4A.Payload_inputstream, wrk_out)

which according to the File.Copy2 documentation automatically closes wrk_AWS_S3_B4A.Payload_inputstream.

So my question/s become:

1. how do I stop File.Copy2 automatically closing wrk_AWS_S3_B4A.Payload_inputstream?
2. alternatively, how can I open wrk_AWS_S3_B4A.Payload_inputstream again?
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I really do wish I could delete a thread.

Turns out the second

Try
File.Copy2(wrk_AWS_S3_B4A.Payload_inputstream, wrk_out)
Catch
Log(LastException)
End Try

was not actually working - its tied up with trying to move a video to a photo gallery when SDK > 29 - and it wasn't actually doing it when I went and looked in the gallery.

I have got around the problem by:

1. copying the input stream to a temporary location

B4X:
                'Move video to temporary location
                wrk_out = File.OpenOutput(File.DirInternal, "temp.mp4", False)
                File.Copy2(wrk_AWS_S3_B4A.Payload_inputstream, wrk_out)
                wrk_out.Close

2. using it multiple times:

B4X:
                wrk_in = File.OpenInput(File.DirInternal, "temp.mp4")
                wrk_out = ...
                File.Copy2(wrk_in, wrk_out)
                wrk_out.Close

3. deleting it:
B4X:
                    File.Delete(File.DirInternal, "temp.mp4")
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…