@Test public void testEncodeContentDisposition() throws Exception { assertEquals("inline; filename=cafe", RFC2231.encodeContentDisposition("cafe", true, null)); assertEquals("inline; filename=mydoc2.txt", RFC2231.encodeContentDisposition("mydoc2.txt", true, null)); assertEquals("inline; filename*=UTF-8''caf%C3%A9", RFC2231.encodeContentDisposition("caf\u00e9", true, TestUserAgent.FF_30)); assertEquals("attachment; filename=caf%C3%A9", RFC2231.encodeContentDisposition("caf\u00e9", false, TestUserAgent.MSIE7_UA)); assertEquals("attachment; filename*=UTF-8''caf%C3%A9", RFC2231.encodeContentDisposition("caf\u00e9", false, null)); assertEquals("attachment; filename*=UTF-8''R%C3%A9sultat%20d%27Activit%C3%A9%20%28%3Bprovisoire%2Fdraft%29.", RFC2231.encodeContentDisposition("R\u00e9sultat d'Activit\u00e9 (;provisoire/draft).", false, TestUserAgent.FF_30)); assertEquals("attachment; filename*=UTF-8''%E5%B9%B3%E4%BB%AE%E5%90%8D%20-%20good.txt", RFC2231.encodeContentDisposition("\u5e73\u4eee\u540d - good.txt", false, TestUserAgent.MSIE11)); assertEquals( "attachment; filename*=UTF-8''%E3%83%8C%E3%82%AF%E3%82%BB%E3%82%AA%E3%83%BB%E3%82%B7%E3%82%99%E3%83%A3%E3%83%8F%E3%82%9A%E3%83%B3.txt", RFC2231.encodeContentDisposition( "\u30cc\u30af\u30bb\u30aa\u30fb\u30b7\u3099\u30e3\u30cf\u309a\u30f3.txt", false, TestUserAgent.SAFARI11)); }
public static String encodeContentDisposition(String filename, boolean inline, String userAgent) { StringBuilder sb = new StringBuilder(); sb.append(inline ? "inline" : "attachment"); sb.append("; filename"); if (userAgent == null) { userAgent = ""; } if (isMSIE6or7(userAgent)) { sb.append("="); percentEscape(sb, filename); } else { encodeRFC2231(sb, filename); } return sb.toString(); }
RFC2231 { public static String encodeContentDisposition(String filename, boolean inline, String userAgent) { StringBuilder sb = new StringBuilder(); sb.append(inline ? "inline" : "attachment"); sb.append("; filename"); if (userAgent == null) { userAgent = ""; } if (isMSIE6or7(userAgent)) { sb.append("="); percentEscape(sb, filename); } else { encodeRFC2231(sb, filename); } return sb.toString(); } }
RFC2231 { public static String encodeContentDisposition(String filename, boolean inline, String userAgent) { StringBuilder sb = new StringBuilder(); sb.append(inline ? "inline" : "attachment"); sb.append("; filename"); if (userAgent == null) { userAgent = ""; } if (isMSIE6or7(userAgent)) { sb.append("="); percentEscape(sb, filename); } else { encodeRFC2231(sb, filename); } return sb.toString(); } private  RFC2231(); }
RFC2231 { public static String encodeContentDisposition(String filename, boolean inline, String userAgent) { StringBuilder sb = new StringBuilder(); sb.append(inline ? "inline" : "attachment"); sb.append("; filename"); if (userAgent == null) { userAgent = ""; } if (isMSIE6or7(userAgent)) { sb.append("="); percentEscape(sb, filename); } else { encodeRFC2231(sb, filename); } return sb.toString(); } private  RFC2231(); static void percentEscape(StringBuilder sb, String value); static String encodeContentDisposition(String filename, boolean inline, String userAgent); }
RFC2231 { public static String encodeContentDisposition(String filename, boolean inline, String userAgent) { StringBuilder sb = new StringBuilder(); sb.append(inline ? "inline" : "attachment"); sb.append("; filename"); if (userAgent == null) { userAgent = ""; } if (isMSIE6or7(userAgent)) { sb.append("="); percentEscape(sb, filename); } else { encodeRFC2231(sb, filename); } return sb.toString(); } private  RFC2231(); static void percentEscape(StringBuilder sb, String value); static String encodeContentDisposition(String filename, boolean inline, String userAgent);  }