File Vs Inpustream in jersey 1.x jaxrs resource
-
21-12-2019 - |
سؤال
Have a need to provide file upload feature using Jax-Rs Jersey-1.x resource. I want to know if its better to create the method with "File" as parameter or "InputStream"?
Resource will accept application/octet-stream
content-type and not tied to form-data.
it will need to work with small to huge size (upto gig) files.
want to know if using InputStream
as method parameter over File
(or vice versa) has any advantage? (ex: memory optimization)
Jersey Runtime server is Tomcat
المحلول
This answer is extremely implementation specific, but from what I remember with both Jersey and CXF, File would make a copy, but is not subject to the vagaries of the HTTP connection, whereas InputStream does NOT make a copy, but could not be passed around to be consumed by other processes (because it's tied to the InputStream of the HTTP Request...)