java.lang.Object
i2p.susi.util.FilenameUtil

public class FilenameUtilextends Object
File name encoding utilities for cross-platform compatibility.
  • Constructor Details

    • FilenameUtil

      public FilenameUtil()
      Constructor. The sanitizers below are static functions of the name they are given, so an instance carries no state.
  • Method Details

    • sanitizeFilename

      public static String sanitizeFilename(String name)
      Convert the UTF-8 to ASCII suitable for inclusion in a header and for use as a cross-platform filename. Replace chars likely to be illegal in filenames, and non-ASCII chars, with _. Ref: RFC 6266, RFC 5987, i2psnark Storage.ILLEGAL
      Parameters:
      name - filename to make ASCII-safe; trimmed, then illegal and non-ASCII chars become _
      Returns:
      the sanitized name, suitable for a header or a cross-platform file
    • encodeFilenameRFC5987

      public static String encodeFilenameRFC5987(String name)
      Encode the UTF-8 suitable for inclusion in a header as a RFC 5987/6266 filename* value, and for use as a cross-platform filename. Replace chars likely to be illegal in filenames with _. Ref: RFC 6266, RFC 5987, i2psnark Storage.ILLEGAL This does NOT do multiline, e.g. filename*0* (RFC 2231) ref: https://blog.nodemailer.com/2017/01/27/the-mess-that-is-attachment-filenames/ ref: RFC 2231
      Parameters:
      name - filename to encode, including any non-ASCII characters
      Returns:
      the RFC 5987 encoded value, prefixed with the "utf-8''" charset
    • decodeFilenameRFC5987

      public static String decodeFilenameRFC5987(String name)
      Decode an RFC 5987 encoded filename back to a string.
      Parameters:
      name - the RFC 5987 encoded filename
      Returns:
      the decoded filename, or name on error