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.
Modifier and Type | Field and Description |
---|---|
static MediaTypeDetector |
DEFAULT
A default media type detector.
|
Constructor and Description |
---|
CompositeMediaTypeDetector(MediaTypeDetector... mediaTypeDetectors)
Initializes a new instance of the
CompositeMediaTypeDetector class. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkMediaType(String mediaType)
Detects whether the
mediaType is supported by the detector. |
String |
detect(InputStream stream)
Detects the media type by the content of the
stream . |
protected String |
detectByContent(InputStream stream)
Detects the media type by the content of the
stream . |
protected String |
detectByExt(String ext)
Detects the media type by the
ext . |
detect, supports
public static final MediaTypeDetector DEFAULT
A default media type detector.
public CompositeMediaTypeDetector(MediaTypeDetector... mediaTypeDetectors)
Initializes a new instance of the CompositeMediaTypeDetector
class.
mediaTypeDetectors
- A collection of MediaTypeDetector
.public String detect(InputStream stream)
MediaTypeDetector
Detects the media type by the content of the stream
.
detect
in class MediaTypeDetector
stream
- Stream of the document.protected String detectByContent(InputStream stream)
Detects the media type by the content of the stream
.
detectByContent
in class MediaTypeDetector
stream
- Stream of the document.protected String detectByExt(String ext)
Detects the media type by the ext
.
detectByExt
in class MediaTypeDetector
ext
- The extension of the file in the UPPER case.protected boolean checkMediaType(String mediaType)
Detects whether the mediaType
is supported by the detector.
checkMediaType
in class MediaTypeDetector
mediaType
- A string with media type in the UPPER case.Copyright © 2018. All rights reserved.