本文整理汇总了Java中org.apache.tika.mime.MimeTypes.forName方法的典型用法代码示例。如果您正苦于以下问题:Java MimeTypes.forName方法的具体用法?Java MimeTypes.forName怎么用?Java MimeTypes.forName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tika.mime.MimeTypes
的用法示例。
在下文中一共展示了MimeTypes.forName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtension
import org.apache.tika.mime.MimeTypes; //导入方法依赖的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();
}
示例2: getExtension
import org.apache.tika.mime.MimeTypes; //导入方法依赖的package包/类
/**
* Dato il content type in input estrapola la vera estensione da dare al file.
* @param contentType
* @author flavio
*/
public String getExtension(String contentType) {
try{
MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
MimeType mime = allTypes.forName(contentType);
return mime.getExtension();
}catch(Exception e){
return "";
}
}
示例3: generatePostParameters
import org.apache.tika.mime.MimeTypes; //导入方法依赖的package包/类
private JSONObject generatePostParameters(String action, String locator, String text, long defaultWait) throws JSONException, IOException, MalformedURLException, MimeTypeException {
JSONObject result = new JSONObject();
String picture = "";
String extension = "";
/**
* Get Picture from URL and convert to Base64
*/
if (locator != null && !"".equals(locator)) {
URL url = new URL(locator);
URLConnection connection = url.openConnection();
InputStream istream = new BufferedInputStream(connection.getInputStream());
/**
* Get the MimeType and the extension
*/
String mimeType = URLConnection.guessContentTypeFromStream(istream);
MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
MimeType mt = allTypes.forName(mimeType);
extension = mt.getExtension();
/**
* Encode in Base64
*/
byte[] bytes = IOUtils.toByteArray(istream);
picture = Base64.encodeBase64URLSafeString(bytes);
}
/**
* Build JSONObject with parameters action : Action expected to be done
* by Sikuli picture : Picture in Base64 format text : Text to type
* defaultWait : Timeout for the action pictureExtension : Extension for
* Base64 decoding
*/
result.put("action", action);
result.put("picture", picture);
result.put("text", text);
result.put("defaultWait", defaultWait);
result.put("pictureExtension", extension);
return result;
}
示例4: doGet
import org.apache.tika.mime.MimeTypes; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
// Pulls the candidateID of the candidate to retrieve photo of
int candidateID = (int) session.getAttribute("candidateID");
// Creates EntityManager to query database
EntityManager em = EMFUtil.getEMFactory().createEntityManager();
// Retrieves user from database based on userID
Candidates candidate = em.find(Candidates.class, candidateID);
// Retrieves resume from candidate's profile.
byte[] pictureBlob = candidate.getPhoto();
// If photo exists
if (pictureBlob != null) {
// Uses APACHE Tika api to obtain MIMETYPE
String mimeType = "";
MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
final Detector DETECTOR = new DefaultDetector(allTypes);
MimeType extension = null;
TikaInputStream tikaIS = null;
try {
tikaIS = TikaInputStream.get(pictureBlob);
final Metadata metadata = new Metadata();
mimeType = DETECTOR.detect(tikaIS, metadata).toString();
extension = allTypes.forName(mimeType);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error getting MIME type");
}
// Tells web-page to prepare and download a picture file
response.setContentType(mimeType);
response.setContentLength(pictureBlob.length);
response.getOutputStream().write(pictureBlob);
response.setHeader("Content-Disposition", "attachment;filename=" + candidateID + extension);
}
}
示例5: getDescription
import org.apache.tika.mime.MimeTypes; //导入方法依赖的package包/类
/**
* Generate ticket description using logs of specified test item.
*
* @param itemIds
* @param ticketRQ
* @return
*/
public String getDescription(Iterable<String> itemIds, PostTicketRQ ticketRQ) {
if (null == itemIds) {
return "";
}
TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
MimeTypes mimeRepository = tikaConfig.getMimeRepository();
StringBuilder descriptionBuilder = new StringBuilder();
for (String itemId : itemIds) {
List<Log> logs = logRepository.findByTestItemRef(itemId, ticketRQ.getNumberOfLogs(), ticketRQ.getIsIncludeScreenshots());
if (null != ticketRQ.getBackLinks().get(itemId) && !ticketRQ.getBackLinks().get(itemId).isEmpty()) {
descriptionBuilder.append(BACK_LINK_HEADER);
descriptionBuilder.append("\n");
descriptionBuilder.append(" - ");
descriptionBuilder.append(String.format(BACK_LINK_PATTERN, ticketRQ.getBackLinks().get(itemId)));
descriptionBuilder.append("\n");
}
// For single test-item only
// TODO add multiple test-items backlinks
if (ticketRQ.getIsIncludeComments() && (ticketRQ.getBackLinks().size() == 1)) {
if (null != ticketRQ.getBackLinks().get(itemId) && !ticketRQ.getBackLinks().get(itemId).isEmpty()) {
TestItem item = itemRepository.findOne(ticketRQ.getTestItemId());
// If test-item contains any comments, then add it for JIRA
// comments section
if ((null != item.getIssue().getIssueDescription()) && (!item.getIssue().getIssueDescription().isEmpty())) {
descriptionBuilder.append(COMMENTS_HEADER);
descriptionBuilder.append("\n");
descriptionBuilder.append(item.getIssue().getIssueDescription());
descriptionBuilder.append("\n");
}
}
}
if (!logs.isEmpty() && (ticketRQ.getIsIncludeLogs() || ticketRQ.getIsIncludeScreenshots())) {
descriptionBuilder.append("h3.*Test execution log:*\n");
descriptionBuilder
.append("{panel:title=Test execution log|borderStyle=solid|borderColor=#ccc|titleColor=#34302D|titleBGColor=#6DB33F}");
for (Log log : logs) {
if (ticketRQ.getIsIncludeLogs()) {
descriptionBuilder.append(CODE).append(getFormattedMessage(log)).append(CODE);
}
if (log.getBinaryContent() != null && ticketRQ.getIsIncludeScreenshots()) {
try {
MimeType mimeType = mimeRepository.forName(log.getBinaryContent().getContentType());
if (log.getBinaryContent().getContentType().contains(IMAGE_CONTENT)) {
descriptionBuilder.append("!").append(log.getBinaryContent().getBinaryDataId())
.append(mimeType.getExtension()).append(IMAGE_HEIGHT_TEMPLATE);
} else {
descriptionBuilder.append("[^").append(log.getBinaryContent().getBinaryDataId())
.append(mimeType.getExtension()).append("]");
}
descriptionBuilder.append(JIRA_MARKUP_LINE_BREAK);
} catch (MimeTypeException e) {
descriptionBuilder.append(JIRA_MARKUP_LINE_BREAK);
LOGGER.error("JIRATicketDescriptionService error: " + e.getMessage(), e);
}
}
}
descriptionBuilder.append("{panel}\n");
}
}
return descriptionBuilder.toString();
}