Class MimeUtil


  • public final class MimeUtil
    extends java.lang.Object
    This MimiUtil can be used to get a MIME type by filenames in a convenient way. Use it like this: MimeUtil.getMimeType("myFile.pdf").
    Author:
    sts
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_MIMETYPE
      The default MIME type to be used if no MIME type matches.
      protected static javax.activation.MimetypesFileTypeMap mimeMap
      The MimetypesFileTypeMap used by this util.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decodeFilename​(java.lang.String filename)
      Decodes a filename encoded by the encodeFilename(String) method.
      static java.lang.String decodeFilename​(javax.servlet.http.HttpServletRequest request, java.lang.String filename)
      Decodes a filename decoded by the encodeFilename(HttpServletRequest, String) method.
      static java.lang.String encodeFilename​(java.lang.String filename)
      Encodes a filename so that it is save for downloading in different browsers.
      static java.lang.String encodeFilename​(javax.servlet.http.HttpServletRequest request, java.lang.String filename)
      Encodes a filename so that it is save for downloading in different browsers.
      static java.lang.String getMimeType​(java.lang.String filename)
      Returns the MIME type matching the given filename.
      protected static void initialize()
      Initializes the MimetypesFileTypeMap used by this util.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_MIMETYPE

        public static final java.lang.String DEFAULT_MIMETYPE
        The default MIME type to be used if no MIME type matches.
        See Also:
        Constant Field Values
      • mimeMap

        protected static javax.activation.MimetypesFileTypeMap mimeMap
        The MimetypesFileTypeMap used by this util.
    • Method Detail

      • initialize

        protected static void initialize()
        Initializes the MimetypesFileTypeMap used by this util.
      • getMimeType

        public static java.lang.String getMimeType​(java.lang.String filename)
        Returns the MIME type matching the given filename.
        Parameters:
        filename - The filename to get the MIME type of.
        Returns:
        the MIME type or "application/octet-stream" if no matching MIME could be found or the util could not be initialized properly.
      • encodeFilename

        public static java.lang.String encodeFilename​(java.lang.String filename)
                                               throws java.io.UnsupportedEncodingException
        Encodes a filename so that it is save for downloading in different browsers. For Internet Explorer, UTF-8 will be used. For other browsers, the filename will be encoded according to RFC 2047. This method can be called from within ZK-context only.
        Parameters:
        filename - the filename to encode
        Returns:
        the encoded filename
        Throws:
        java.io.UnsupportedEncodingException - if the encoding used to encode the filename is unknown
      • decodeFilename

        public static java.lang.String decodeFilename​(java.lang.String filename)
                                               throws java.io.UnsupportedEncodingException
        Decodes a filename encoded by the encodeFilename(String) method.
        Parameters:
        filename - the filename to decoded
        Returns:
        the decoded filename
        Throws:
        java.io.UnsupportedEncodingException - if the encoding used to decode the filename is unknown
      • encodeFilename

        public static java.lang.String encodeFilename​(javax.servlet.http.HttpServletRequest request,
                                                      java.lang.String filename)
                                               throws java.io.UnsupportedEncodingException
        Encodes a filename so that it is save for downloading in different browsers. For Internet Explorer, UTF-8 will be used. For other browsers, the filename will be encoded according to RFC 2047. This method can be called from without ZK-context.
        Parameters:
        request - the current request
        filename - the filename to encode
        Returns:
        the encoded filename
        Throws:
        java.io.UnsupportedEncodingException - if the encoding used to encode the filename is unknown
      • decodeFilename

        public static java.lang.String decodeFilename​(javax.servlet.http.HttpServletRequest request,
                                                      java.lang.String filename)
                                               throws java.io.UnsupportedEncodingException
        Decodes a filename decoded by the encodeFilename(HttpServletRequest, String) method.
        Parameters:
        request - the current request
        filename - the filename to decoded
        Returns:
        the decoded filename
        Throws:
        java.io.UnsupportedEncodingException - if the encoding used to decode the filename is unknown