Apache commons fileupload "Streaming API"

I quote the Apache Commons page for Commons FileUpload

This page describes the traditional API for downloading community library files. The traditional API is a convenient approach. However, for maximum performance, you may prefer the Streaming API faster .

My question

What specific differences make the Streaming API faster than the traditional API ?

+4
source share
4 answers

The main difference is how you process the file, as you noticed yourself with the factory class.

The streaming API is not stored on disk when an input stream is received. In the end, you can process the file faster (with a cost in temporary memory) ... but the idea is to avoid saving the binary disk to disk if you really do not want / need it.

After that, you can save the data to disk, of course, using a buffer stream, a byte array, or the like.

EDIT: a handler when opening a stream (fileItemStreamElement. OpenStream ()) is a normal instance of InputStream. So, the answer to your question β€œwhat if it is a large file” looks like this. Memory problems with InputStream in Java

EDIT: The streaming API should not save to disk or store in memory. It just provides a stream that you can read to copy the file to where you want. This is a way to avoid a temporary directory and also not allocate enough memory to store the file. This should be faster, at least because it is not copied twice, once from the browser to disk / memory, and then again from disk / memory to where you saved it.

+4
source

The traditional API described in the User Guide assumes that the elements of the file must be stored somewhere before they are actually available to the user. This approach is convenient because it provides easy access to the content of elements. On the other hand, it is memory and takes a lot of time.

http://commons.apache.org/fileupload/streaming.html

0
source

The streaming API should not be stored on disk or stored in memory. It just provides a stream that you can read to copy the file to where you want. This is a way to avoid a temporary directory and also not allocate enough memory to store the file. This should be faster, at least because it is not copied twice, once from the browser to disk / memory, and then again from disk / memory to where you saved it.

0
source

Streaming usually refers to an API (e.g., Apache FileUpload or StAX) in which data is transferred and analyzed sequentially during application execution, often in real time, and often from dynamic sources whose contents are not known in advance.

Traditional models refer to APIs, for example (traditional file processing APIs, DOM APIs), which provide much more detailed information about the data.

As with the FileHandling API. The traditional approach assumes that the elements of the file must be stored somewhere before they are actually available to the user. This approach is convenient because it provides easy access to the content of elements. On the other hand, it is memory and takes a lot of time.

The streaming API will have a smaller memory size and lower processor requirements and may have better performance in certain situations.

He works on the main kind of "cardboard tube" of the document with which you work.

-1
source

All Articles