Class MimeTypeInfoManager


  • @ThreadSafe
    @Singleton
    public class MimeTypeInfoManager
    extends Object
    This is the central manager for all MimeTypeInfo objects.
    Author:
    Philip Helger
    • Constructor Detail

      • MimeTypeInfoManager

        public MimeTypeInfoManager()
        Create a new empty (!!) instance.
    • Method Detail

      • isDefaultInstantiated

        public static boolean isDefaultInstantiated()
      • read

        @Nonnull
        public MimeTypeInfoManager read​(@Nonnull
                                        com.helger.commons.io.resource.IReadableResource aRes)
        Read the information from the specified resource.
        Parameters:
        aRes - The resource to read. May not be null.
        Returns:
        this
      • clearCache

        @Nonnull
        public com.helger.commons.state.EChange clearCache()
        Remove all registered mime types
        Returns:
        EChange.
      • reinitializeToDefault

        public void reinitializeToDefault()
      • getAllInfosOfFilename

        @Nullable
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfFilename​(@Nullable
                                                                                                   File aFile)
      • getAllInfosOfExtension

        @Nullable
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfExtension​(@Nullable
                                                                                                    String sExtension)
        Get all infos associated with the specified filename extension.
        Parameters:
        sExtension - The extension to search. May be null or empty.
        Returns:
        null if the passed extension is null or if no such extension is registered.
      • getAllInfosOfMimeType

        @Nullable
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllInfosOfMimeType​(@Nullable
                                                                                                   com.helger.commons.mime.IMimeType aMimeType)
        Get all infos associated with the passed mime type.
        Parameters:
        aMimeType - The mime type to search. May be null.
        Returns:
        null if a null mime type was passed or the passed mime type is unknown.
      • getAllMimeTypeInfos

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<MimeTypeInfo> getAllMimeTypeInfos()
        Returns:
        A non-null set with all mime types infos known to this instance.
      • getAllMimeTypes

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsOrderedSet<com.helger.commons.mime.IMimeType> getAllMimeTypes()
        Returns:
        A non-null set with all mime types known to this instance.
      • getAllMimeTypeStrings

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllMimeTypeStrings()
        Returns:
        A non-null set with all mime types known to this instance.
      • containsMimeTypeForFilename

        public boolean containsMimeTypeForFilename​(@Nonnull @Nonempty
                                                   String sFilename)
        Check if any mime type is registered for the extension of the specified filename.
        Parameters:
        sFilename - The filename to search. May neither be null nor empty.
        Returns:
        true if at least one mime type is associated with the extension of the passed filename, false otherwise.
      • getAllMimeTypesForFilename

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsSet<com.helger.commons.mime.IMimeType> getAllMimeTypesForFilename​(@Nonnull @Nonempty
                                                                                                                            String sFilename)
        Get all mime types that are associated to the extension of the specified filename.
        Parameters:
        sFilename - The filename to search. May neither be null nor empty.
        Returns:
        Never null but maybe empty set if no mime type is associated with the extension of the passed filename.
      • getAllMimeTypeStringsForFilename

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsSet<String> getAllMimeTypeStringsForFilename​(@Nonnull @Nonempty
                                                                                                       String sFilename)
        Get all mime types that are associated to the extension of the specified filename.
        Parameters:
        sFilename - The filename to search. May neither be null nor empty.
        Returns:
        Never null but maybe empty set if no mime type is associated with the extension of the passed filename.
      • getPrimaryMimeTypeForFilename

        @Nullable
        public com.helger.commons.mime.IMimeType getPrimaryMimeTypeForFilename​(@Nonnull @Nonempty
                                                                               String sFilename)
        Get the primary (=first) mime type associated with the specified filename.
        Parameters:
        sFilename - The filename to retrieve the primary mime type from. May neither be null nor empty.
        Returns:
        null if no mime type is associated with the extension of the passed filename
      • getPrimaryMimeTypeStringForFilename

        @Nullable
        public String getPrimaryMimeTypeStringForFilename​(@Nonnull @Nonempty
                                                          String sFilename)
        Get the primary (=first) mime type associated with the specified filename.
        Parameters:
        sFilename - The filename to retrieve the primary mime type from. May neither be null nor empty.
        Returns:
        null if no mime type is associated with the extension of the passed filename
      • containsMimeTypeForExtension

        public boolean containsMimeTypeForExtension​(@Nonnull
                                                    String sExtension)
        Check if any mime type is associated with the passed extension
        Parameters:
        sExtension - The filename extension to search. May not be null.
        Returns:
        true if at least one mime type is associated, false if no mime type is associated with the extension
      • getAllMimeTypesForExtension

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsOrderedSet<com.helger.commons.mime.IMimeType> getAllMimeTypesForExtension​(@Nonnull
                                                                                                                                    String sExtension)
        Get all mime types that are associated to the specified filename extension.
        Parameters:
        sExtension - The filename extension to search. May not be null.
        Returns:
        Never null but maybe empty set if no mime type is associated with the passed extension.
      • getAllMimeTypeStringsForExtension

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllMimeTypeStringsForExtension​(@Nonnull
                                                                                                               String sExtension)
        Get all mime types that are associated to the specified filename extension.
        Parameters:
        sExtension - The filename extension to search. May not be null.
        Returns:
        Never null but maybe empty set if no mime type is associated with the passed extension.
      • getPrimaryMimeTypeForExtension

        @Nullable
        public com.helger.commons.mime.IMimeType getPrimaryMimeTypeForExtension​(@Nonnull
                                                                                String sExtension)
        Get the primary (=first) mime type that is associated to the specified filename extension.
        Parameters:
        sExtension - The filename extension to search. May not be null.
        Returns:
        null if no mime type is associated with the passed extension.
      • getPrimaryMimeTypeStringForExtension

        @Nullable
        public String getPrimaryMimeTypeStringForExtension​(@Nonnull
                                                           String sExtension)
        Get the primary (=first) mime type that is associated to the specified filename extension.
        Parameters:
        sExtension - The filename extension to search. May not be null.
        Returns:
        null if no mime type is associated with the passed extension.
      • getAllExtensionsOfMimeType

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllExtensionsOfMimeType​(@Nullable
                                                                                                        com.helger.commons.mime.IMimeType aMimeType)
        Get all extensions associated to the specified mime type
        Parameters:
        aMimeType - The mime type to search. May be null.
        Returns:
        Never null but empty set if no extensions are present.
      • getPrimaryExtensionOfMimeType

        @Nullable
        public String getPrimaryExtensionOfMimeType​(@Nullable
                                                    com.helger.commons.mime.IMimeType aMimeType)
        Get the primary (=first) extension for the specified mime type.
        Parameters:
        aMimeType - The mime type to be searched. May be null.
        Returns:
        null if the mime type has no file extension assigned
      • getAllGlobsOfMimeType

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsOrderedSet<String> getAllGlobsOfMimeType​(@Nullable
                                                                                                   com.helger.commons.mime.IMimeType aMimeType)
        Get all globs (=filename patterns) associated to the specified mime type
        Parameters:
        aMimeType - The mime type to search. May be null.
        Returns:
        Never null but empty set if no globs are present.