Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download InputStream #10

Open
llyppi opened this issue May 11, 2022 · 10 comments
Open

Download InputStream #10

llyppi opened this issue May 11, 2022 · 10 comments

Comments

@llyppi
Copy link

llyppi commented May 11, 2022

project.downloadObject
InputStream close after 64mg writed
Works if use ByteStreams.copy(download, out)
But that away its needed write byte[] in server side,after create InputStream to download client side
It would be better to send Inputstream directly to the client side response to download object

@mniewrzal
Copy link
Collaborator

I'm not sure I understand main problem. Could you give me a code sample to visualize it?

@llyppi
Copy link
Author

llyppi commented May 12, 2022

code
code.zip

@Erikvv
Copy link

Erikvv commented May 12, 2022

Thanks for your report!

InputStream close after 64mg writed

At 64 MiB int ObjectInputStream.read(byte[]) will return 0 because there are no more bytes in the segment. You need to call read(byte[]) again to start reading the next segment.

This looks like a bug, it doesn't satisfy the specification:

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/InputStream.html#read(byte%5B%5D,int,int):
(...)
at least one byte is read and stored into b

For sure we also have a bug in int ObjectInputStream.read() which throws IOException("invalid state") at 64 MiB.

@Erikvv
Copy link

Erikvv commented May 12, 2022

Works if use ByteStreams.copy(download, out)
But that away its needed write byte[] in server side,after create InputStream to download client side
It would be better to send Inputstream directly to the client side response to download object

It sounds like you're asking for an API change because you think it would be faster. Is ObjectInputStream.transferTo(OutputStream) maybe suitable? I don't think you'll be able to measure a difference though.

@mniewrzal mniewrzal moved this to Backlog in Metainfo Team May 13, 2022
@llyppi
Copy link
Author

llyppi commented May 13, 2022

FileInputStream works good but its need exist file in server side to download
Better case is on the moment open
ObjectInputStream download = project.downloadObject(bucket, new File(file).getName());
use that InputStream download and redirect to response client side
No needed write file in server and after create FileInputStream

@Erikvv
Copy link

Erikvv commented May 13, 2022

I'm sorry. I don't understand your use case and proposal.

@llyppi
Copy link
Author

llyppi commented May 13, 2022

I have a panel web to explorer my buckets
When client side request download, first the object will be write o server in file,after FileInputstream return response to client request
But that away all object will stored in server, not good
Using ByteOutputstream the memory server its out of memory

@Erikvv
Copy link

Erikvv commented May 15, 2022

I have a panel web to explorer my buckets
When client side request download, first the object will be write o server in file,after FileInputstream return response to client request
But that away all object will stored in server, not good
Using ByteOutputstream the memory server its out of memory

"Doctor it hurts when I move like this"
-> "Then don't move like that"

It looks you can use jakarta.servlet.http.HttpServletResponse.getOutputStream() to immediately write from the HTTP server to the client, without storing anything on the server.

Your HTTP server framework may even accept an InputStream directly like io.javalin.http.Context.result(InputStream resultStream)

(FWIW, I'm not a Java guru)

@Erikvv
Copy link

Erikvv commented May 15, 2022

With regards to the 0 bytes at 64 MiB, created storj/uplink#99

@llyppi
Copy link
Author

llyppi commented May 26, 2022

i try owerite close method
Untitled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

No branches or pull requests

3 participants