当前位置: 首页>>代码示例>>Java>>正文


Java MimeTypeException类代码示例

本文整理汇总了Java中org.apache.tika.mime.MimeTypeException的典型用法代码示例。如果您正苦于以下问题:Java MimeTypeException类的具体用法?Java MimeTypeException怎么用?Java MimeTypeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MimeTypeException类属于org.apache.tika.mime包,在下文中一共展示了MimeTypeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMimeTypeForMediaTypeSafe

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * Returns the top tika mime-type definition for the media type.
 * WARN: this only returns explicit defined mime-types (canonical), NOT aliases.
 * if exact true, will double-check that parameters match as well (not guaranteed by MimeTypes.getRegisteredMimeType).
 * FIXME: exact doesn't handle parameter order.
 */
public static MimeType getMimeTypeForMediaTypeSafe(String mediaType, MimeTypes mimeTypes, boolean exact) {
    try {
        MimeType mimeType = mimeTypes.getRegisteredMimeType(mediaType);
        if (mimeType != null && exact) {
            // NOTE: because the way getRegisteredMimeType works, it may return non-null
            // even if not exact name match, due to parameters.
            // FIXME: this check won't handle parameter order difference
            // also check if another normalize call would be more appropriate...
            if (!getMimeTypeId(mediaType).equals(getMimeTypeId(mimeType.getName()))) {
                return null;
            }
        }
        return mimeType;
    } catch (MimeTypeException e) {
        return null;
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:24,代码来源:TikaUtil.java

示例2: embedding

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
@Override
public void embedding(String mimeType, byte[] data) {
	File file = new File();
	String embeddingName;
	try {
		embeddingName = MimeTypes.getDefaultMimeTypes().forName(mimeType).getType().getType();
	} catch (MimeTypeException e) {
		LOGGER.warn("Mime-type not found", e);
		embeddingName = "embedding";
	}

	file.setName(embeddingName);
	file.setContent(data);

	Utils.sendLog(embeddingName, "UNKNOWN", file);
}
 
开发者ID:reportportal,项目名称:agent-java-cucumber,代码行数:17,代码来源:AbstractReporter.java

示例3: parseEmbedded

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * Processa i contenuti
 *
 * @since 1.1: aggiunto il trattamento dei TIFF
 * @param stream stream binario del contenuto
 * @param handler handler
 * @param metadata metadati del documento
 * @param outputHtml necessario per l'override del metodo ma mai usato
 * @throws SAXException eccezione
 * @throws IOException Eccezione di input/output
 */
@Override
public void parseEmbedded(InputStream stream, org.xml.sax.ContentHandler handler, Metadata metadata, boolean outputHtml) throws SAXException, IOException {
    String name = "Content" + fileCount++;
    MediaType contentType = detector.detect(stream, metadata);
    if (contentType != null) {
        try {
            name += config.getMimeRepository().forName(contentType.toString()).getExtension();
        } catch (MimeTypeException e) {
            LogGui.printException(e);
        }
    }
    byte[] bytes = IOUtils.toByteArray(stream);
    embedded.put(name, bytes);
    if (name.toLowerCase().endsWith("jpg") || name.toLowerCase().endsWith("tiff") || name.toLowerCase().endsWith("tif") || name.toLowerCase().endsWith("png") || name.toLowerCase().endsWith("gif")) {

        BufferedImage pl = ImageIO.read(new ByteArrayInputStream(bytes));
        if (pl != null) {
            if ((pl.getWidth() > 32 && pl.getHeight() > 32)) //No Icone
            {
                embeddedImages.put(name, pl);
            }
        }

    }
}
 
开发者ID:fiohol,项目名称:theSemProject,代码行数:37,代码来源:SemEmbeddedDocumentsExtractor.java

示例4: getAsFile

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
public java.io.File getAsFile() throws ClientHandlerException,
		UniformInterfaceException, IOException, MimeTypeException,
		ClientException, ServerException {
	ClientResponse cr = wd.path3(path).getAsOctetStream(
			ClientResponse.class);
	checkError(cr);
	String[] bits = localName().split("[.]");
	String ext = getDefaultMimeTypes().forName(
			cr.getHeaders().getFirst("Content-Type")).getExtension();
	if (ext == null)
		ext = bits[bits.length - 1];
	java.io.File tmp = createTempFile(bits[0], ext);
	try (OutputStream os = new FileOutputStream(tmp);
			InputStream is = cr.getEntity(InputStream.class)) {
		copy(is, os);
	}
	return tmp;
}
 
开发者ID:apache,项目名称:incubator-taverna-server,代码行数:19,代码来源:File.java

示例5: MimeTypeGroupDef

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
public MimeTypeGroupDef(final String... mimeTypes) {
	_mimeTypes = Collections2.transform(CollectionUtils.of(mimeTypes).asCollection(),
										new Function<String,org.apache.tika.mime.MimeType>() {
												@Override
												public org.apache.tika.mime.MimeType apply(final String mimeTypeName) {
													try {
														return MIME_TYPES.get().forName(mimeTypeName);
													} catch (MimeTypeException mimeEx) {
														mimeEx.printStackTrace();
													}
													return null;
												}
										});
	_extensions = new HashMap<org.apache.tika.mime.MimeType,Collection<String>>();
	for (org.apache.tika.mime.MimeType mimeType : _mimeTypes) {
		Collection<String> extensions = mimeType.getExtensions();
		if (CollectionUtils.hasData(extensions)) _extensions.put(mimeType,extensions);
	}
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:20,代码来源:MimeTypes.java

示例6: getExtension

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * Determines extension to use for the given mime type.
 * <p>Current implementation is based on <i>Apache Tika</i>. If the given mime type is not recognized no extension
 * will be returned
 *
 * @param   mimeType   The mime type to get the extensio for
 * @return             The default extension for the given mime type<br>or <code>null</code> when the mime type is
 *                     not recognized
 */
public static String getExtension(final String mimeType) {
    if (mimeType == null || mimeType.isEmpty())
        return null;

    final MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
    MimeType  tikaMimeType = null;
    try {
        tikaMimeType = allTypes.forName(mimeType);
    } catch (final MimeTypeException ex) {
        // Can not detect the mime type of the given file, so no extension
        return null;
    }

    return tikaMimeType.getExtension();
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:25,代码来源:Utils.java

示例7: extensionForMIME

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
public static String extensionForMIME(String mimeType) {
    if (mimeType.isEmpty())
        return DEFAULT_EXT;

    MimeType mime = null;
    try {
        mime = MimeTypes.getDefaultMimeTypes().forName(mimeType);
    } catch (MimeTypeException ex) {
        LOGGER.log(Level.WARNING, "can't find mimetype", ex);
    }

    String m = mime != null ? mime.getExtension() : "";
    // remove dot
    if (!m.isEmpty())
        m = m.substring(1);
    return StringUtils.defaultIfEmpty(m, DEFAULT_EXT);
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:18,代码来源:MediaUtils.java

示例8: getExtension

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * Get the preferred file extension for the content type
 *
 * @param mimeType mimeType
 * @return file extension (already including '.')
 */
public static String getExtension(String mimeType) {
    final String defaultExt = ".bin";
    final MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
    try {
        final String ext = allTypes.forName(mimeType).getExtension();
        log.trace("Tika's file-extension for {} is '{}'", mimeType, ext);
        if (StringUtils.isNotBlank(ext)) {
            return ext;
        }
    } catch (MimeTypeException e) {
        log.trace("MimeTypeException: {}. Not critical, recovering...", e.getMessage());
    }
    log.trace("Using fallback file-extension '{}' for {}", defaultExt, mimeType);
    return defaultExt;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:22,代码来源:LdpUtils.java

示例9: getExtension

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
@Override
public String getExtension(String mimetype)
{
    try
    {
        MimeType tikaMimeType = tikaConfig.getMimeRepository().forName(mimetype);
        if (tikaMimeType != null)
        {
            String tikaExtension = tikaMimeType.getExtension();
            if (tikaExtension.startsWith("."))
            {
                tikaExtension = tikaExtension.substring(1, tikaExtension.length());
            }
            return tikaExtension;
        }
    }
    catch (MimeTypeException e)
    {
        throw new GytheioRuntimeException("Could not get extension for mimetype", e);
    }
    
    return null;
}
 
开发者ID:Alfresco,项目名称:gytheio,代码行数:24,代码来源:FileMediaTypeServiceImpl.java

示例10: getNameWithExt

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
public static String getNameWithExt(String filename, String mimeType) {
  // Check if the current extension is good enough
  final scala.Option<String> expected = MimeTypes.forFileName(filename);
  if (expected.isDefined() && expected.get().equals(mimeType)) {
    return filename;
  }
  // We need to add on an extension that conveys the mime type.
  try {
    final org.apache.tika.mime.MimeTypes mimeTypes =
        TikaConfig.getDefaultConfig().getMimeRepository();
    final String ext = mimeTypes.forName(mimeType).getExtension();
    if (!ext.isEmpty()) {
      return filename+ext;
    }
  } catch (MimeTypeException e) {
    // Fall through
  }
  // We gave it our best shot.
  return filename;
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:21,代码来源:FileStoreHelper.java

示例11: parseMimeType

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * Parses a mime type using apache tika which can handle the following:
 * http://svn.apache.org/repos/asf/tika/trunk/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml
 */
private static String parseMimeType(@Nullable String format) {
  if (format != null) {
    format = Strings.emptyToNull(format.trim().toLowerCase());
  }

  try {
    MimeType mime = MIME_TYPES.getRegisteredMimeType(format);
    if (mime != null) {
      return mime.getName();
    }

  } catch (MimeTypeException e) {
  }

  // verify this is a reasonable mime type
  return format == null || MimeType.isValid(format) ? format : null;
}
 
开发者ID:gbif,项目名称:checklistbank,代码行数:22,代码来源:MediaTypeUtils.java

示例12: setMIMEType

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * Set the MIME type of a found link, i.e., once you'ved downloaded the content you then know the ContentType
 * possibly.
 * Which may differ from your perception of the URL path
 * 
 * - reset the file extension,
 * - reset the path
 * - folder vs. file
 * 
 * Set the MIME Type, file type, path, etc... prior to saving content to disk.
 *
 * @param t
 *            the new MIME type
 */
public void setMIMEType(String t) {
    mimeType = t;
    if (mimeType == null) {
        return;
    }

    try {
        MimeType mt;
        /* Isolate the MIME type without parameters.
         * 
         */
        mt = defaultMIME.forName(t.split(";", 2)[0]);
        if (mt != null) {
            fixPathExtension(mt.getExtension());
        }
    } catch (MimeTypeException ignore) {
        // Hmm.
    }
}
 
开发者ID:OpenSextant,项目名称:Xponents,代码行数:34,代码来源:HyperLink.java

示例13: getMimeType

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
public static String getMimeType(CloseableHttpResponse response) {
    try {
        MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
        return allTypes.forName(response.getEntity().getContentType().getValue()).getExtension();
    } catch (MimeTypeException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:java-webbee,项目名称:webBee,代码行数:10,代码来源:HttpUtil.java

示例14: forName

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
/**
 * A facade interface to Tika's underlying {@link MimeTypes#forName(String)}
 * method.
 * 
 * @param name
 *          The name of a valid {@link MimeType} in the Tika mime registry.
 * @return The object representation of the {@link MimeType}, if it exists, or
 *         null otherwise.
 */
public String forName(String name) {
  try {
    return this.mimeTypes.forName(name).toString();
  } catch (MimeTypeException e) {
    LOG.error("Exception getting mime type by name: [" + name
        + "]: Message: " + e.getMessage());
    return null;
  }
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:19,代码来源:MimeUtil.java

示例15: getExtension

import org.apache.tika.mime.MimeTypeException; //导入依赖的package包/类
static String getExtension(String contentType){
	try {
		return MimeTypes.getDefaultMimeTypes().forName(contentType).getExtension();
	} catch (MimeTypeException e) {
		//TODO find another exception
		throw new RuntimeException(String.format("Unable to resolve content type '%s'", contentType), e);
	}
}
 
开发者ID:reportportal,项目名称:service-tfs,代码行数:9,代码来源:TfsUtils.java


注:本文中的org.apache.tika.mime.MimeTypeException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。