I’m working on some requirements that will lead to arbitrary PDF files being downloaded from a J2EE web server. The names may look like this:
Xxxxxxxxxxxxxxxxxx – Yyyyyyyyyy – Aaaaaaaaaaa – Bbbbbbbb ccc Dddddddddddddd – abc1234560 – 2009-03-26 – 235959.pdf
Now I’ve read a couple of sections in RFC2183:
http://www.ietf.org/rfc/rfc2183.txt
For instance
A short (length <= 78 characters) parameter value containing
only non-tspecials' characters SHOULD be represented as a singletoken’. A short parameter value containing only ASCII characters,
but includingtspecials' characters, SHOULD be represented asquoted-string’. Parameter values longer than 78 characters, or
which contain non-ASCII characters, MUST be encoded as specified in
[RFC 2184].
Etc etc. Now there are millions of things that can go wrong, if I don’t read through all of those RFC’s… Or I choose a library which handles such RFC specifications. Is there any such thing for Java? Or am I paranoid, and actually it’s sufficient to just write this header to the out stream:
String filename = "\"" + filename.replace("\"", "\\\"") + "\"";
addHeader("Content-Disposition", "attachment; filename=" + filename);
RFC 2183 isn’t relevant, RFC 6266 is.
Also, the 78 character limit only applies to email, not http, so you don’t have to worry about that.