com.groupdocs.parser

Interfaces

Classes

Exceptions

com.groupdocs.parser

Class CompositeMediaTypeDetector



  • public final class CompositeMediaTypeDetector
    extends MediaTypeDetector

    Provides the functionality to detect various media types.

    For detecting media type of any document type CompositeMediaTypeDetector is used:

     // Create a composite media type detector
     MediaTypeDetector detector = CompositeMediaTypeDetector.DEFAULT;
     // Detect a media type
     String mediaType = detector.detect(stream);
      

    Default property contains all supported media type detectors.

     MediaTypeDetector detector = new CompositeMediaTypeDetector(
         new MediaTypeDetector[]
         {
             new CellsMediaTypeDetector(), // media type detector of a spreadsheet
             new WordsMediaTypeDetector(), // media type detector of a text document
             new SlidesMediaTypeDetector(), // media type detector of a presentation
         }
     );
      

    It detects only media type of spreadsheets, presentations and text documents.

    • Field Detail

      • DEFAULT

        public static final MediaTypeDetector DEFAULT

        A default media type detector.

    • Constructor Detail

      • CompositeMediaTypeDetector

        public CompositeMediaTypeDetector(MediaTypeDetector... mediaTypeDetectors)

        Initializes a new instance of the CompositeMediaTypeDetector class.

        Parameters:
        mediaTypeDetectors - A collection of MediaTypeDetector.
    • Method Detail

      • detect

        public String detect(InputStream stream)
        Description copied from class: MediaTypeDetector

        Detects the media type by the content of the stream.

        Overrides:
        detect in class MediaTypeDetector
        Parameters:
        stream - Stream of the document.
        Returns:
        A string with the media type if the media type is detected; otherwise, null.
      • detectByContent

        protected String detectByContent(InputStream stream)

        Detects the media type by the content of the stream.

        Overrides:
        detectByContent in class MediaTypeDetector
        Parameters:
        stream - Stream of the document.
        Returns:
        A string with the media type if the media type is detected; otherwise, null.
      • detectByExt

        protected String detectByExt(String ext)

        Detects the media type by the ext.

        Specified by:
        detectByExt in class MediaTypeDetector
        Parameters:
        ext - The extension of the file in the UPPER case.
        Returns:
        A string with the media type if the media type is detected; otherwise, null.
      • checkMediaType

        protected boolean checkMediaType(String mediaType)

        Detects whether the mediaType is supported by the detector.

        Specified by:
        checkMediaType in class MediaTypeDetector
        Parameters:
        mediaType - A string with media type in the UPPER case.
        Returns:
        A boolean true if the media type is supported; otherwise, false.