InputStream stream, ContentHandler handler,
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
DataInputStream datainput = new DataInputStream(stream);
if (!checkSignature(datainput)) {
throw new TikaException("FLV signature not detected");
}
// header
int version = datainput.readUnsignedByte();
if (version != 1) {
// should be 1, perhaps this is not flv?
throw new TikaException("Unpexpected FLV version: " + version);
}
int typeFlags = datainput.readUnsignedByte();
long len = readUInt32(datainput);
if (len != 9) {
// we only know about format with header of 9 bytes
throw new TikaException("Unpexpected FLV header length: " + len);
}
long sizePrev = readUInt32(datainput);
if (sizePrev != 0) {
// should be 0, perhaps this is not flv?
throw new TikaException(
"Unpexpected FLV first previous block size: " + sizePrev);
}
metadata.set(Metadata.CONTENT_TYPE, "video/x-flv");
metadata.set("hasVideo", Boolean.toString((typeFlags & MASK_VIDEO) != 0));