Package org.apache.tika

Examples of org.apache.tika.Tika.detect()


        // requested a specific resource
        String file = StringUtils.getLastPathElement(requestedPath);
        try {
          // query Tika for the content type
          Tika tika = new Tika();
          String contentType = tika.detect(file);

          if (contentType == null) {
            // ask the container for the content type
            contentType = context.getMimeType(requestedPath);
View Full Code Here


    @Test
    public void testBundleDetection(BundleContext bc) throws Exception {
        Tika tika = new Tika();

        // Simple type detection
        assertEquals("text/plain", tika.detect("test.txt"));
        assertEquals("application/pdf", tika.detect("test.pdf"));
    }

    @Ignore // TODO Fix this test
    @Test
View Full Code Here

    public void testBundleDetection(BundleContext bc) throws Exception {
        Tika tika = new Tika();

        // Simple type detection
        assertEquals("text/plain", tika.detect("test.txt"));
        assertEquals("application/pdf", tika.detect("test.pdf"));
    }

    @Ignore // TODO Fix this test
    @Test
    public void testBundleSimpleText(BundleContext bc) throws Exception {
View Full Code Here

      // If no mime-type header, or cannot find a corresponding registered
      // mime-type, then guess a mime-type from the url pattern
      try {
        TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
        Tika tika = new Tika(tikaConfig);
        retType = tika.detect(url) != null ? tika.detect(url) : null;
      } catch (Exception e) {
        String message = "Problem loading default Tika configuration";
        LOG.error(message, e);
        throw new RuntimeException(e);
      }
View Full Code Here

      // If no mime-type header, or cannot find a corresponding registered
      // mime-type, then guess a mime-type from the url pattern
      try {
        TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
        Tika tika = new Tika(tikaConfig);
        retType = tika.detect(url) != null ? tika.detect(url) : null;
      } catch (Exception e) {
        String message = "Problem loading default Tika configuration";
        LOG.error(message, e);
        throw new RuntimeException(e);
      }
View Full Code Here

    // if magic is enabled use mime magic to guess if the mime type returned
    // from the magic guess is different than the one that's already set so far
    // if it is, and it's not the default mime type, then go with the mime type
    // returned by the magic
    if (this.mimeMagic) {
      magicType = tika.detect(data);

      // Deprecated in Tika 1.0 See https://issues.apache.org/jira/browse/NUTCH-1230
      //MimeType magicType = this.mimeTypes.getMimeType(data);
      if (magicType != null && !magicType.equals(MimeTypes.OCTET_STREAM)
          && !magicType.equals(MimeTypes.PLAIN_TEXT)
View Full Code Here

    public void validateImageFormat(byte[] bytes) throws ImageFormatException {
        Validate.notNull(bytes, "Incoming byte array cannot be null");
        Tika tika = new Tika();
        InputStream input = new ByteArrayInputStream(bytes);
        try {
            String type = tika.detect(input);
            if (!VALID_IMAGE_TYPES.contains(type)) {
                LOGGER.debug("Wrong file extension. May be only {}", VALID_IMAGE_EXTENSIONS);
                throw new ImageFormatException(VALID_IMAGE_EXTENSIONS);
            }
        } catch (IOException e) {
View Full Code Here

    public BufferedImage convertByteArrayToImage(byte[] bytes) throws ImageProcessException {
        BufferedImage result;
        BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(bytes));
        Tika tika = new Tika();
        try {
            String type = tika.detect(bis);
            if (type.contains(ImageService.ICO_TYPE)) {
                result = ICODecoder.read(bis).get(0);
            } else {
                result = ImageIO.read(bis);
            }
View Full Code Here

    @Test
    public void testTikaBundle(BundleContext bc) throws Exception {
        Tika tika = new Tika();

        // Simple type detection
        assertEquals("text/plain", tika.detect("test.txt"));
        assertEquals("application/pdf", tika.detect("test.pdf"));

        // Simple text extraction
        String xml = tika.parseToString(new File("pom.xml"));
        assertTrue(xml.contains("tika-bundle"));
View Full Code Here

    public void testTikaBundle(BundleContext bc) throws Exception {
        Tika tika = new Tika();

        // Simple type detection
        assertEquals("text/plain", tika.detect("test.txt"));
        assertEquals("application/pdf", tika.detect("test.pdf"));

        // Simple text extraction
        String xml = tika.parseToString(new File("pom.xml"));
        assertTrue(xml.contains("tika-bundle"));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.