I have been attempting to find a servlet file framework that provides a bit more than just reading a file setting the appropriate headers and thats it. There are countless samples available on the net most are quite elementary and very few (almost none) support something more complex as i will describe below.
HTTP
Http provides much more rich features such as - ranges which help implement file download resumes. - cache control via etags and last modified dates.
Googling
However i cannot find anything more than a simple file servlet example. Unfortunately "Java File Download Servlet Framework" and other similar combinations, is a very overloaded form and most of the time Google returns web frameworks and not something that makes it easy to support some or all the advanced features previously mentioned.
Thinking...
Just off the top of my head the framework would provide an interface like this:
FileProvider {
Date lastModified();
INputStream inputStream();
String etag();
...
}
If anyone knows of a framework that separates all the nasty bits of reading headers and comparing values that would be great.
The best source i could find to get one started is
http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html
but unfrotunately the sample has no provision for inserting a FileProvider and assumes that the path info from the request maps to a file on disk in some directory.
Apache Tomcat's DefaultServlet might have most of what you're looking for. At a glance, I see ETag parsing and AcceptRange handling.
http://www.docjar.com/html/api/org/apache/catalina/servlets/DefaultServlet.java.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With