EncodingUtils { public static String encodeFilename(final String filename, final String userAgent) { String codedFilename = null; try { if (null != userAgent && -1 != userAgent.indexOf("MSIE")) { codedFilename = URLEncoder.encode(filename, DEFAULT_CHARSET); } else if (null != userAgent && -1 != userAgent.indexOf("Mozilla")) { codedFilename = MimeUtility.encodeText(filename, DEFAULT_CHARSET, "B"); } } catch (UnsupportedEncodingException uee) { } return codedFilename != null ? codedFilename : filename; } private  EncodingUtils(); static String encode(final String str); static String encodeUrl(final String url); static String encodeUri(final String uri); static String encodeFilename(final String filename, final String userAgent);  }
@Test public void testEncodeFilename() throws Exception { assertEquals("file", EncodingUtils.encodeFilename("file", "MSIE")); assertEquals("file", EncodingUtils.encodeFilename("file", "Mozilla")); assertEquals("a+b", EncodingUtils.encodeFilename("a b", "MSIE")); assertEquals("a b", EncodingUtils.encodeFilename("a b", "Mozilla")); assertEquals("%23", EncodingUtils.encodeFilename("#", "MSIE")); assertEquals("#", EncodingUtils.encodeFilename("#", "Mozilla")); assertEquals("%C3%A5%C3%A4%C3%B6", EncodingUtils.encodeFilename("åäö", "MSIE")); assertEquals("=?UTF-8?B?w6XDpMO2?=", EncodingUtils.encodeFilename("åäö", "Mozilla")); assertEquals("%C3%BC", EncodingUtils.encodeFilename("\u00fc", "MSIE")); assertEquals("=?UTF-8?B?w7w=?=", EncodingUtils.encodeFilename("\u00fc", "Mozilla")); }