I am trying to find a servlet framework that provides a little more than just reading a file setting the appropriate headers, and that is it. There are countless samples available on the net, most of them are fairly basic, and very few (almost none) support something more complex, as I will describe below.
HTTP
Http provides much richer features, such as ranges, that help you implement file uploads. - cache management through etags and last modified dates.
Googling
However, I cannot find anything but a simple example file. Unfortunately, the “Java File Download Servlet Framework” and other similar combinations are a very overloaded form, and most of the time Google returns web frameworks, rather than making it easier to support some or all of the additional features mentioned earlier.
Thinking ...
From the very beginning, my infrastructure would provide such an interface:
FileProvider { Date lastModified(); INputStream inputStream(); String etag(); ... }
- FileProvider takes the path to the file and resolves it in a real file, possibly something from the database, etc.
- if the file has not changed (determined by reading FileProvider.lastModifier (), which it has.
- If the request requests a range, then f / w will read FileProvider.inputStream (), writing only the ranges of interest to the HttpServletResponse.
- The etag value will be used during the negotiation phase to determine if ranges are supported, etc.
- there is another interface for the "creation" of FileProvider with the path, etc.
If anyone knows a structure that separates all the ugly bits of read headers and compares values that would be large.
The best source I could find to get started is
http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html
but, unfortunately, the FileProvider insert is not provided in the sample and it is assumed that the path information from the request is mapped to a file on disk in some directory.
source share