title: How do I correctly set the HTTP Content-Disposition for large file names in Java?
body: <p>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:</p>
  
  <blockquote>
    <p>Xxxxxxxxxxxxxxxxxx - Yyyyyyyyyy - Aaaaaaaaaaa - Bbbbbbbb ccc Dddddddddddddd - abc1234560 - 2009-03-26 – 235959.pdf</p>
  </blockquote>
  
  <p>Now I've read a couple of sections in RFC2183:</p>
  
  <p><a href="http://www.ietf.org/rfc/rfc2183.txt" rel="nofollow">http://www.ietf.org/rfc/rfc2183.txt</a></p>
  
  <p>For instance</p>
  
  <blockquote>
    <p>A short (length &lt;= 78 characters)    parameter value containing
    only non-<code>tspecials' characters SHOULD be    represented as a single
    </code>token'.  A short parameter value containing    only ASCII characters,
    but including <code>tspecials' characters, SHOULD    be represented as
    </code>quoted-string'.  Parameter values longer than 78    characters, or
    which contain non-ASCII characters, MUST be encoded as    specified in
    [RFC 2184].</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code>String filename = "\"" + filename.replace("\"", "\\\"") + "\"";
  addHeader("Content-Disposition", "attachment; filename=" + filename);
  </code></pre>