@Test public void testEncodeContentDisposition() throws Exception { assertEquals(MimeUtility.encodeWord("1.jpg"), "1.jpg"); }
public static String encodeContentDisposition(String userAgent, String fileName) { try { String lowUserAgent = userAgent.toLowerCase(); if (lowUserAgent.contains("msie") || lowUserAgent.contains("trident")) { return "attachment;filename=" + StringUtils.replace(URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()), "+", "%20"); } else if (lowUserAgent.contains("opera")) { return "attachment;filename*=UTF-8''" + fileName; } else if (lowUserAgent.contains("safari") || lowUserAgent.contains("applewebkit") || lowUserAgent.contains("mozilla")) { return "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); } else { return "attachment;filename=" + MimeUtility.encodeWord(fileName); } } catch (UnsupportedEncodingException e) { String charset = MimeUtility.getDefaultJavaCharset(); throw new RuntimeException("default java charset [" + charset + "]", e); } }
WebUtil { public static String encodeContentDisposition(String userAgent, String fileName) { try { String lowUserAgent = userAgent.toLowerCase(); if (lowUserAgent.contains("msie") || lowUserAgent.contains("trident")) { return "attachment;filename=" + StringUtils.replace(URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()), "+", "%20"); } else if (lowUserAgent.contains("opera")) { return "attachment;filename*=UTF-8''" + fileName; } else if (lowUserAgent.contains("safari") || lowUserAgent.contains("applewebkit") || lowUserAgent.contains("mozilla")) { return "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); } else { return "attachment;filename=" + MimeUtility.encodeWord(fileName); } } catch (UnsupportedEncodingException e) { String charset = MimeUtility.getDefaultJavaCharset(); throw new RuntimeException("default java charset [" + charset + "]", e); } } }
WebUtil { public static String encodeContentDisposition(String userAgent, String fileName) { try { String lowUserAgent = userAgent.toLowerCase(); if (lowUserAgent.contains("msie") || lowUserAgent.contains("trident")) { return "attachment;filename=" + StringUtils.replace(URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()), "+", "%20"); } else if (lowUserAgent.contains("opera")) { return "attachment;filename*=UTF-8''" + fileName; } else if (lowUserAgent.contains("safari") || lowUserAgent.contains("applewebkit") || lowUserAgent.contains("mozilla")) { return "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); } else { return "attachment;filename=" + MimeUtility.encodeWord(fileName); } } catch (UnsupportedEncodingException e) { String charset = MimeUtility.getDefaultJavaCharset(); throw new RuntimeException("default java charset [" + charset + "]", e); } }  }
WebUtil { public static String encodeContentDisposition(String userAgent, String fileName) { try { String lowUserAgent = userAgent.toLowerCase(); if (lowUserAgent.contains("msie") || lowUserAgent.contains("trident")) { return "attachment;filename=" + StringUtils.replace(URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()), "+", "%20"); } else if (lowUserAgent.contains("opera")) { return "attachment;filename*=UTF-8''" + fileName; } else if (lowUserAgent.contains("safari") || lowUserAgent.contains("applewebkit") || lowUserAgent.contains("mozilla")) { return "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); } else { return "attachment;filename=" + MimeUtility.encodeWord(fileName); } } catch (UnsupportedEncodingException e) { String charset = MimeUtility.getDefaultJavaCharset(); throw new RuntimeException("default java charset [" + charset + "]", e); } }  static String guessContentType(String fileName); static String encodeContentDisposition(String userAgent, String fileName); }
WebUtil { public static String encodeContentDisposition(String userAgent, String fileName) { try { String lowUserAgent = userAgent.toLowerCase(); if (lowUserAgent.contains("msie") || lowUserAgent.contains("trident")) { return "attachment;filename=" + StringUtils.replace(URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()), "+", "%20"); } else if (lowUserAgent.contains("opera")) { return "attachment;filename*=UTF-8''" + fileName; } else if (lowUserAgent.contains("safari") || lowUserAgent.contains("applewebkit") || lowUserAgent.contains("mozilla")) { return "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); } else { return "attachment;filename=" + MimeUtility.encodeWord(fileName); } } catch (UnsupportedEncodingException e) { String charset = MimeUtility.getDefaultJavaCharset(); throw new RuntimeException("default java charset [" + charset + "]", e); } }  static String guessContentType(String fileName); static String encodeContentDisposition(String userAgent, String fileName);  }