org.apache.tika.mime.MimeTypesFactory Java Examples

The following examples show how to use org.apache.tika.mime.MimeTypesFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TikaFilePlace.java    From emissary with Apache License 2.0 6 votes vote down vote up
/**
 * Set up place specific information from the config file, load JNI, etc.
 */
protected void configurePlace() throws IOException {

    configureIdPlace(); // pick up ID_IGNORE types
    tikaSignaturePaths = configG.findEntries("TIKA_SIGNATURE_FILE", DEFAULT_TIKA_SIGNATURE_FILE);
    includeFilenameMimeType = configG.findBooleanEntry("INCLUDE_FILENAME_MIME_TYPE", includeFilenameMimeType);

    try {
        InputStream[] tikaSignatures = getTikaSignatures();
        mimeTypes = MimeTypesFactory.create(tikaSignatures);
    } catch (MimeTypeException e) {
        logger.error("Error loading tika configuration: " + tikaSignaturePaths.toString(), e);
        throw new IOException("Error loading tika configuration" + tikaSignaturePaths.toString());
    }

    for (Map.Entry<String, String> entry : configG.findStringMatchMap("MIN_SIZE_").entrySet()) {
        try {
            minSizeMap.put(entry.getKey(), Integer.parseInt(entry.getValue()));
        } catch (NumberFormatException ex) {
            logger.info("Must be numeric MIN_SIZE_" + entry.getKey() + " = " + entry.getValue());
        }
    }
}
 
Example #2
Source File: MimeTypeUtils.java    From oodt with Apache License 2.0 5 votes vote down vote up
public MimeTypeUtils(InputStream mimeIs, boolean magic) {
	try {
		this.mimeTypes = MimeTypesFactory.create(mimeIs);
		this.mimeMagic = magic;
		this.tika = new Tika(new DefaultDetector(this.mimeTypes));
	}catch (Exception e) {
		LOG.log(Level.SEVERE, "Failed to load MimeType Registry : " + e.getMessage(), e);
	}
}
 
Example #3
Source File: LocalDataTransferer.java    From oodt with Apache License 2.0 4 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) throws DataTransferException,
      IOException, URISyntaxException {
   String usage = "LocalFileTransfer --productName <name> --productRepo <repo> [--dir <dirRef>] [--files <origRef 1>...<origRef N>]\n";

   MimeTypes mimeTypeRepo;
   try {
      mimeTypeRepo = MimeTypesFactory
            .create(System
                  .getProperty("org.apache.oodt.cas.filemgr.mime.type.repository"));
   } catch (MimeTypeException e) {
      LOG.log(Level.SEVERE, e.getMessage());
      throw new IOException(e.getMessage());
   }

   String productName = null;
   String productRepo = null;
   String transferType = null;
   Reference dirReference = null;

   List<Reference> fileReferences = null;

   for (int i = 0; i < args.length; i++) {
      if (args[i].equals("--dir")) {
         transferType = "dir";
         dirReference = new Reference();
         dirReference.setOrigReference(new File(new URI(args[++i])).toURI()
               .toString());
         LOG.log(Level.FINER,
               "LocalFileTransfer.main: Generated orig reference: "
                     + dirReference.getOrigReference());
      } else if (args[i].equals("--files")) {
         transferType = "files";
         fileReferences = new Vector<Reference>();
         for (int j = i + 1; j < args.length; j++) {
            LOG.log(Level.FINER, "LocalFileTransfer.main: Adding file ref: "
                  + args[j]);
            fileReferences.add(new Reference(args[j], null,
                  new File(args[j]).length(), mimeTypeRepo
                        .getMimeType(args[j])));
         }
      } else if (args[i].equals("--productName")) {
         productName = args[++i];
      } else if (args[i].equals("--productRepo")) {
         productRepo = args[++i];
      }
   }

   if (transferType == null || (((transferType.equals("dir") && dirReference == null) || (
       transferType.equals("files") && fileReferences == null) || (!(
       transferType.equals("dir") || transferType
           .equals("files"))) || productName == null || productRepo == null))) {
      System.err.println(usage);
      System.exit(1);
   }

   // construct a new Product
   Product p = new Product();
   p.setProductName(productName);

   if (transferType.equals("dir")) {
      p.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
      dirReference.setDataStoreReference(new File(new URI(productRepo))
            .toURI().toURL().toExternalForm()
            + URLEncoder.encode(p.getProductName(), "UTF-8") + "/");
      p.getProductReferences().add(dirReference);
      /* we'll do a simple versioning scheme ourselves: no versioning! */
      p.getProductReferences().addAll(
            VersioningUtils.getReferencesFromDir(new File(new URI(
                  dirReference.getOrigReference()))));
      VersioningUtils.createBasicDataStoreRefsHierarchical(p
            .getProductReferences());
   } else if (transferType.equals("files")) {
      p.setProductStructure("Flat");
      p.getProductReferences().addAll(fileReferences);
      VersioningUtils.createBasicDataStoreRefsFlat(productName, productRepo,
            p.getProductReferences());
   }

   DataTransfer transfer = new LocalDataTransferer();
   transfer.transferProduct(p);

}