Search in sources :

Example 76 with Metadata

use of org.apache.tika.metadata.Metadata in project tika by apache.

the class AudioParserTest method testWAV.

@Test
public void testWAV() throws Exception {
    String path = "/test-documents/testWAV.wav";
    Metadata metadata = new Metadata();
    String content = new Tika().parseToString(AudioParserTest.class.getResourceAsStream(path), metadata);
    assertEquals("audio/x-wav", metadata.get(Metadata.CONTENT_TYPE));
    assertEquals("44100.0", metadata.get("samplerate"));
    assertEquals("2", metadata.get("channels"));
    assertEquals("16", metadata.get("bits"));
    assertEquals("PCM_SIGNED", metadata.get("encoding"));
    assertEquals("", content);
}
Also used : Metadata(org.apache.tika.metadata.Metadata) Tika(org.apache.tika.Tika) Test(org.junit.Test)

Example 77 with Metadata

use of org.apache.tika.metadata.Metadata in project tika by apache.

the class Pkcs7ParserTest method testDetachedSignature.

public void testDetachedSignature() throws Exception {
    try (InputStream input = Pkcs7ParserTest.class.getResourceAsStream("/test-documents/testDetached.p7s")) {
        ContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();
        new Pkcs7Parser().parse(input, handler, metadata, new ParseContext());
    } catch (NullPointerException npe) {
        fail("should not get NPE");
    } catch (TikaException te) {
        assertTrue(te.toString().contains("cannot parse detached pkcs7 signature"));
    }
}
Also used : BodyContentHandler(org.apache.tika.sax.BodyContentHandler) TikaException(org.apache.tika.exception.TikaException) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) ParseContext(org.apache.tika.parser.ParseContext) BodyContentHandler(org.apache.tika.sax.BodyContentHandler) ContentHandler(org.xml.sax.ContentHandler)

Example 78 with Metadata

use of org.apache.tika.metadata.Metadata in project tika by apache.

the class SourceCodeParserTest method createMetadata.

private Metadata createMetadata(String mimeType) {
    Metadata metadata = new Metadata();
    metadata.add(Metadata.RESOURCE_NAME_KEY, "testFile");
    metadata.add(Metadata.CONTENT_TYPE, mimeType);
    return metadata;
}
Also used : Metadata(org.apache.tika.metadata.Metadata)

Example 79 with Metadata

use of org.apache.tika.metadata.Metadata in project tika by apache.

the class DBFParserTest method testVariants.

@Test
public void testVariants() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (InputStream is = getResourceAsStream("/test-documents/testDBF.dbf")) {
        IOUtils.copy(is, bos);
    }
    byte[] bytes = bos.toByteArray();
    for (DBFReader.Version version : DBFReader.Version.values()) {
        //this cast happens to work because of the range of possible values
        bytes[0] = (byte) version.getId();
        XMLResult r = getXML(TikaInputStream.get(bytes), new AutoDetectParser(), new Metadata());
        assertEquals(version.getFullMimeString(), r.metadata.get(Metadata.CONTENT_TYPE));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TikaInputStream(org.apache.tika.io.TikaInputStream) InputStream(java.io.InputStream) Metadata(org.apache.tika.metadata.Metadata) AutoDetectParser(org.apache.tika.parser.AutoDetectParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) TikaTest(org.apache.tika.TikaTest)

Example 80 with Metadata

use of org.apache.tika.metadata.Metadata in project tika by apache.

the class ExecutableParserTest method testElfParser_x86_32.

@Test
public void testElfParser_x86_32() throws Exception {
    XMLResult r = getXML("testLinux-x86-32");
    Metadata metadata = r.metadata;
    assertEquals("application/x-executable", metadata.get(Metadata.CONTENT_TYPE));
    assertEquals(ExecutableParser.MACHINE_x86_32, metadata.get(ExecutableParser.MACHINE_TYPE));
    assertEquals("Little", metadata.get(ExecutableParser.ENDIAN));
    assertEquals("32", metadata.get(ExecutableParser.ARCHITECTURE_BITS));
    //         assertEquals("Linux",
    //               metadata.get(ExecutableParser.PLATFORM));
    assertContains("<body />", r.xml);
}
Also used : Metadata(org.apache.tika.metadata.Metadata) Test(org.junit.Test) TikaTest(org.apache.tika.TikaTest)

Aggregations

Metadata (org.apache.tika.metadata.Metadata)651 Test (org.junit.Test)467 InputStream (java.io.InputStream)320 ParseContext (org.apache.tika.parser.ParseContext)283 BodyContentHandler (org.apache.tika.sax.BodyContentHandler)269 TikaTest (org.apache.tika.TikaTest)257 ContentHandler (org.xml.sax.ContentHandler)229 AutoDetectParser (org.apache.tika.parser.AutoDetectParser)154 ByteArrayInputStream (java.io.ByteArrayInputStream)143 Parser (org.apache.tika.parser.Parser)136 TikaInputStream (org.apache.tika.io.TikaInputStream)133 IOException (java.io.IOException)66 DefaultHandler (org.xml.sax.helpers.DefaultHandler)59 TikaException (org.apache.tika.exception.TikaException)48 ExcelParserTest (org.apache.tika.parser.microsoft.ExcelParserTest)36 WordParserTest (org.apache.tika.parser.microsoft.WordParserTest)36 StringWriter (java.io.StringWriter)33 Tika (org.apache.tika.Tika)29 MediaType (org.apache.tika.mime.MediaType)29 SAXException (org.xml.sax.SAXException)29