Class MimeTypeDeterminator


  • @ThreadSafe
    @Singleton
    public final class MimeTypeDeterminator
    extends Object
    Contains a basic set of MimeType determination method.
    Author:
    Philip Helger
    • Field Detail

      • DEFAULT_MIME_TYPE

        public static final IMimeType DEFAULT_MIME_TYPE
    • Method Detail

      • isInstantiated

        public static boolean isInstantiated()
      • registerMimeTypeContent

        @Nonnull
        public EChange registerMimeTypeContent​(@Nonnull
                                               MimeTypeContent aMimeTypeContent)
        Register a new MIME content type.
        Parameters:
        aMimeTypeContent - The content type to register. May not be null.
        Returns:
        EChange.CHANGED if the object was successfully registered.
      • unregisterMimeTypeContent

        @Nonnull
        public EChange unregisterMimeTypeContent​(@Nullable
                                                 MimeTypeContent aMimeTypeContent)
        Unregister an existing MIME content type.
        Parameters:
        aMimeTypeContent - The content type to unregister. May not be null.
        Returns:
        EChange.CHANGED if the object was successfully unregistered.
      • getMimeTypeFromString

        @Nonnull
        public IMimeType getMimeTypeFromString​(@Nullable
                                               String s,
                                               @Nonnull
                                               Charset aCharset)
        Try to find the MIME type that matches the passed content string.
        Parameters:
        s - The content string to check. May be null.
        aCharset - The charset used to convert the string to a byte array. May not be null.
        Returns:
        DEFAULT_MIME_TYPE if no matching MIME type was found. Never null.
      • getMimeTypeFromString

        @Nullable
        public IMimeType getMimeTypeFromString​(@Nullable
                                               String s,
                                               @Nonnull
                                               Charset aCharset,
                                               @Nullable
                                               IMimeType aDefault)
        Try to find the MIME type that matches the passed content string.
        Parameters:
        s - The content string to check. May be null.
        aCharset - The charset used to convert the string to a byte array. May not be null.
        aDefault - The default MIME type to be returned, if no MIME type could be found. May be null.
        Returns:
        aDefault if no matching MIME type was found. May be null.
      • getMimeTypeFromBytes

        @Nonnull
        public IMimeType getMimeTypeFromBytes​(@Nullable
                                              byte[] b)
        Try to determine the MIME type from the given byte array.
        Parameters:
        b - The byte array to parse. May be null or empty.
        Returns:
        DEFAULT_MIME_TYPE if no specific MIME type was found. Never null.
      • getMimeTypeFromBytes

        @Nullable
        public IMimeType getMimeTypeFromBytes​(@Nullable
                                              byte[] aBytes,
                                              @Nullable
                                              IMimeType aDefault)
        Try to determine the MIME type from the given byte array.
        Parameters:
        aBytes - The byte array to parse. May be null or empty.
        aDefault - The default MIME type to be returned, if no matching MIME type was found. May be null.
        Returns:
        The supplied default value, if no matching MIME type was found. May be null.