public class SimpleMimeTypeDetector extends Object implements MimeTypeDetector
MimeTypeDetector
implementation.
It's ad-hoc and not customizable, just tested against many samples.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SNIFF_LENGTH
default value for
sniffLength . |
protected static int |
MINIMUM_SNIFF_BUFFER_SIZE
minimum size of sniffing byte buffer to allocate (to
prevent
ArrayIndexOutOfBoundsException .) |
Constructor and Description |
---|
SimpleMimeTypeDetector() |
Modifier and Type | Method and Description |
---|---|
protected String |
detectCSS(String text) |
protected String |
detectHTML(String text) |
protected String |
detectJavaScript(String text) |
int |
getSniffLength() |
protected byte[] |
peekContent(Resource resource)
Read first
sniffLength bytes of resource 's payload,
decoding Content-Encoding if any. |
void |
setCharsetDetector(CharsetDetector charsetDetector)
CharsetDetector to use for detecting character encoding. |
void |
setSniffLength(int sniffLength)
number of bytes to read from resource.
|
String |
sniff(Resource resource) |
public static final int DEFAULT_SNIFF_LENGTH
sniffLength
.protected static final int MINIMUM_SNIFF_BUFFER_SIZE
ArrayIndexOutOfBoundsException
.)public void setSniffLength(int sniffLength)
sniffLength
- public int getSniffLength()
public void setCharsetDetector(CharsetDetector charsetDetector)
CharsetDetector
to use for detecting character encoding.
StandardCharsetDetector
is used by default.
charsetDetector
- protected byte[] peekContent(Resource resource) throws IOException
sniffLength
bytes of resource
's payload,
decoding Content-Encoding
if any. Reset resource
's
read position back to zero.resource
- Resource to load bytes fromIOException
public String sniff(Resource resource)
sniff
in interface MimeTypeDetector
Copyright © 2005–2017 IIPC. All rights reserved.