Package org.apache.tika.mime

Examples of org.apache.tika.mime.MimeTypes


     */
    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) {
          e.printStackTrace();
          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")) {
View Full Code Here


    */
   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) {
         e.printStackTrace();
         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")) {
View Full Code Here

  /* our log stream */
  private static final Logger LOG = Logger.getLogger(MimeUtil.class.getName());

  public MimeUtil(Configuration conf) {
    ObjectCache objectCache = ObjectCache.get(conf);
    MimeTypes mimeTypez = (MimeTypes) objectCache.getObject(MimeTypes.class
        .getName());
    if (mimeTypez == null) {
      mimeTypez = MimeTypesFactory.create(conf
          .getConfResourceAsInputStream(conf.get("mime.types.file")));
      objectCache.setObject(MimeTypes.class.getName(), mimeTypez);
View Full Code Here

    */
   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) {
         e.printStackTrace();
         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")) {
View Full Code Here

                                .append(extension).toString());
    }

    private static String getFileExtension(String mimeType) {
        if (StringUtils.isEmpty(mimeType)) return "";
        MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
        try {
            MimeType type = allTypes.forName(mimeType);
            return type.getExtension();
        }
        catch (MimeTypeException e) {
            return "";
        }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(MimeUtil.class.getName());

  public MimeUtil(Configuration conf) {
    tika = new Tika();
    ObjectCache objectCache = ObjectCache.get(conf);
    MimeTypes mimeTypez = (MimeTypes) objectCache.getObject(MimeTypes.class
        .getName());
    if (mimeTypez == null) {
      try {
          String customMimeTypeFile = conf.get("mime.types.file");
          if (customMimeTypeFile!=null && customMimeTypeFile.equals("")==false){
View Full Code Here

  /* our log stream */
  private static final Logger LOG = Logger.getLogger(MimeUtil.class.getName());

  public MimeUtil(Configuration conf) {
    ObjectCache objectCache = ObjectCache.get(conf);
    MimeTypes mimeTypez = (MimeTypes) objectCache.getObject(MimeTypes.class
        .getName());
    if (mimeTypez == null) {
      try {
        mimeTypez = MimeTypesFactory.create(conf
            .getConfResourceAsInputStream(conf.get("mime.types.file")));
View Full Code Here

*/
public class EntityUtils {

    public static MultipartEntity getMultipartEntity(Map<File, String> files)
            throws MimeTypeException, IOException {
        MimeTypes mimeTypes = TikaConfig.getDefaultConfig().getMimeRepository();
        MultipartEntity multipartEntity = new MultipartEntity();

        int x = 0;
       
        for (Map.Entry<File, String> entry : files.entrySet()) {
            String name = entry.getValue();
            File file = entry.getKey();

            byte[] buf = IOUtils.toByteArray(new FileInputStream(file));
            MediaType mediaType = mimeTypes.
                    detect(new ByteArrayInputStream(buf), new Metadata());
            MimeType mimeType = mimeTypes.forName(mediaType.toString());
            FileBody fb = new FileBody(file, name + mimeType.getExtension(),
                    mimeType.getName(), Consts.UTF_8.name());

            multipartEntity.addPart("files[" + x + "]", fb);
            x++;
View Full Code Here

  /* our log stream */
  private static final Logger LOG = LoggerFactory.getLogger(MimeUtil.class.getName());

  public MimeUtil(Configuration conf) {
    ObjectCache objectCache = ObjectCache.get(conf);
    MimeTypes mimeTypez = (MimeTypes) objectCache.getObject(MimeTypes.class
        .getName());
    if (mimeTypez == null) {
      try {
          String customMimeTypeFile = conf.get("mime.types.file");
          if (customMimeTypeFile!=null && customMimeTypeFile.equals("")==false){
View Full Code Here

     *
     * @param mimeType mimeType
     * @return file extension (already including '.')
     */
    public static String getExtension(String mimeType) {
        MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
        try {
            return allTypes.forName(mimeType).getExtension();
        } catch (MimeTypeException e) {
            return null; //FIXME
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.tika.mime.MimeTypes

Copyright © 2018 www.massapicom. 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.