List of usage examples for javax.activation MimeType MimeType
public MimeType(String rawdata) throws MimeTypeParseException
From source file:eu.fusepool.p3.transformer.sample.SimpleAsyncTransformer.java
@Override public Set<MimeType> getSupportedInputFormats() { try {// w w w. jav a2 s .c o m MimeType mimeType = new MimeType("text/plain"); return Collections.singleton(mimeType); } catch (MimeTypeParseException ex) { throw new RuntimeException(ex); } }
From source file:ddf.catalog.impl.operations.MetacardFactory.java
Metacard generateMetacard(String mimeTypeRaw, String id, String fileName, Path tmpContentPath) throws MetacardCreationException, MimeTypeParseException { Metacard generatedMetacard = null;// w w w . jav a2 s .co m MimeType mimeType = new MimeType(mimeTypeRaw); List<InputTransformer> listOfCandidates = mimeTypeToTransformerMapper.findMatches(InputTransformer.class, mimeType); List<String> stackTraceList = new ArrayList<>(); LOGGER.debug("List of matches for mimeType [{}]: {}", mimeType, listOfCandidates); for (InputTransformer candidate : listOfCandidates) { try (InputStream transformerStream = com.google.common.io.Files.asByteSource(tmpContentPath.toFile()) .openStream()) { generatedMetacard = candidate.transform(transformerStream); } catch (CatalogTransformerException | IOException e) { List<String> stackTraces = Arrays.asList(ExceptionUtils.getRootCauseStackTrace(e)); stackTraceList.add(String.format("Transformer [%s] could not create metacard.", candidate)); stackTraceList.addAll(stackTraces); LOGGER.debug("Transformer [{}] could not create metacard.", candidate, e); } if (generatedMetacard != null) { break; } } if (generatedMetacard == null) { throw new MetacardCreationException(String.format("Could not create metacard with mimeType %s : %s", mimeTypeRaw, StringUtils.join(stackTraceList, "\n"))); } if (id != null) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, id)); } else { generatedMetacard.setAttribute(new AttributeImpl(Metacard.ID, uuidGenerator.generateUuid())); } if (StringUtils.isBlank(generatedMetacard.getTitle())) { generatedMetacard.setAttribute(new AttributeImpl(Metacard.TITLE, fileName)); } return generatedMetacard; }
From source file:mitm.common.mail.MimeUtils.java
/** * Parses the contentType and returns the Java Charset found in the content type. Null if charset * parameter is not found.//w w w . j a v a 2 s .c om */ public static String getCharsetFromContentType(String contentType) throws MimeTypeParseException { MimeType mimeType = new MimeType(contentType); String charset = mimeType.getParameter("charset"); return StringUtils.isNotEmpty(charset) ? MimeUtility.javaCharset(charset) : null; }
From source file:org.apache.abdera2.test.client.MultipartRelatedEntityTest.java
License:asdf
@Test public void testMultimediaRelatedContentType() throws Exception { MimeType type = new MimeType("Multipart/Related;boundary=\"35245352345sdfg\""); assertTrue(MimeTypeHelper.isMatch("Multipart/Related", type.toString())); assertEquals("35245352345sdfg", type.getParameter("boundary")); }
From source file:eu.fusepool.p3.transformer.sample.SimpleAsyncTransformer.java
private MimeType getOutputMimeType() { try {// ww w .j ava 2s .c o m MimeType mimeType = new MimeType("text/plain;stamped=true"); return mimeType; } catch (MimeTypeParseException ex) { throw new RuntimeException(ex); } }
From source file:com.github.restdriver.serverdriver.http.RequestBody.java
private ContentType createContentType(String contentType) { try {/* w w w . j a va2s . c om*/ MimeType mimeType = new MimeType(contentType); String mediaType = mimeType.getBaseType(); String charset = defaultString(mimeType.getParameter("charset"), DEFAULT_CONTENT_ENCODING); return ContentType.create(mediaType, charset); } catch (MimeTypeParseException e) { throw new IllegalArgumentException("Invalid content type: " + contentType, e); } }
From source file:ddf.camel.component.catalog.inputtransformer.InputTransformerProducer.java
protected Object transform(Message in, Object obj, String mimeType, String transformerId, MimeTypeToTransformerMapper mapper) throws MimeTypeParseException, IOException, CatalogTransformerException { // Look up the InputTransformer for the request's mime type. // If a transformer is found, then transform the request's payload into // a Metacard. // Otherwise, throw an exception. MimeType derivedMimeType = new MimeType(mimeType); if (transformerId != null) { derivedMimeType = new MimeType( mimeType + ";" + MimeTypeToTransformerMapper.ID_KEY + "=" + transformerId); }//from w ww.j av a 2 s.c o m InputStream message = null; Metacard metacard = null; try { message = in.getBody(InputStream.class); if (null != message) { metacard = generateMetacard(derivedMimeType, mapper, message); } else { throw new CatalogTransformerException("Message body was null; unable to generate Metacard!"); } } catch (MetacardCreationException e) { throw new CatalogTransformerException("Did not find an InputTransformer for MIME Type [" + mimeType + "] and " + MimeTypeToTransformerMapper.ID_KEY + " [" + transformerId + "]", e); } finally { if (null != message) { IOUtils.closeQuietly(message); } } return metacard; }
From source file:org.opensextant.xtext.converters.test.MessageConverterTest.java
@Test public void complexEmailTest() throws Exception { MessageConverter conv = new MessageConverter(); ConvertedDocument doc = conv.convert(TEST_FILE); Assert.assertEquals((MESSAGE_BODY + MESSAGE_BOUNDARY).trim(), doc.getText()); Assert.assertEquals(5, doc.getRawChildren().size()); final HashMap<String, Content> children = new HashMap<String, Content>(); for (final Content child : doc.getRawChildren()) { children.put(child.id, child);//w ww . ja v a 2 s .co m } Content text_attach = children.get("xtext-embedded-attached-text.txt"); Assert.assertNotNull("text attachment was not found, available attachments are: " + children.keySet(), text_attach); String orig_text_attach = IOUtils .toString(getClass().getResourceAsStream("xtext-embedded-attached-text.txt"), "UTF-8"); String sep = System.getProperty("line.separator"); if (!"\r\n".equals(sep)) { orig_text_attach = orig_text_attach.replaceAll(sep, "\r\n"); } Assert.assertEquals("text/plain", new MimeType(text_attach.mimeType).getBaseType()); Assert.assertEquals(orig_text_attach, new String(text_attach.content, text_attach.encoding)); Assert.assertEquals("A686FA7D9F4FB64E99601455209639C5@imc.mitre.org", text_attach.meta.getProperty(CONTENT_ID)); Assert.assertEquals("attachment", text_attach.meta.getProperty(CONTENT_DISPOSITION)); Content html_attach = children.get("word_doc_as_html.htm"); Assert.assertNotNull("Embedded HTML was not found.", html_attach); Assert.assertEquals("text/html", new MimeType(html_attach.mimeType).getBaseType()); Assert.assertEquals("64B706D14F6CAF4598A5A756E2E763A0@imc.mitre.org", html_attach.meta.getProperty(CONTENT_ID)); Assert.assertEquals("attachment", html_attach.meta.getProperty(CONTENT_DISPOSITION)); Content word_attach = children.get("doc_with_embedded_geocoded_image2.docx"); Assert.assertNotNull("Doc with geocoded image was not found.", word_attach); Assert.assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", new MimeType(word_attach.mimeType).getBaseType()); Assert.assertEquals("3ED3B89ABF3D1840B551B527B4DA054D@imc.mitre.org", word_attach.meta.getProperty(CONTENT_ID)); Assert.assertEquals("attachment", word_attach.meta.getProperty(CONTENT_DISPOSITION)); Content jpeg_attach = children.get("android_photo_with_gps1.jpeg"); Assert.assertNotNull("Photo with attached image was not found.", jpeg_attach); Assert.assertEquals("image/jpeg", new MimeType(jpeg_attach.mimeType).getBaseType()); Assert.assertEquals("485710da-7b60-461a-a566-0ad2e0a14b82@imc.mitre.org", jpeg_attach.meta.getProperty(CONTENT_ID)); Assert.assertEquals("inline", jpeg_attach.meta.getProperty(CONTENT_DISPOSITION)); Content htmlbody = null; for (final Content child : doc.getRawChildren()) { if ("true".equals(child.meta.getProperty(MessageConverter.MAIL_KEY_PREFIX + "html-body"))) { Assert.assertNull("multiple html bodies found", htmlbody); Assert.assertEquals("text/html", new MimeType(child.mimeType).getBaseType()); Assert.assertEquals("BEA4D58835C6A342B10D665B40F9D105@imc.mitre.org", child.meta.getProperty(CONTENT_ID)); htmlbody = child; } } Assert.assertNotNull("html body was not found", htmlbody); }
From source file:ddf.catalog.source.opensearch.SecureRemoteConnectionImpl.java
@Override public BinaryContent getData(String urlStr) throws IOException { URL url = new URL(urlStr); URLConnection conn = url.openConnection(); if (conn instanceof HttpsURLConnection) { try {//w ww . j a v a 2 s. c o m ((HttpsURLConnection) conn).setSSLSocketFactory(getSocketFactory()); } catch (Exception e) { throw new IOException("Error in creating SSL socket.", e); } } conn.connect(); MimeType mimeType = DEFAULT_MIMETYPE; try { mimeType = new MimeType(conn.getContentType()); } catch (MimeTypeParseException e) { LOGGER.debug("Error creating mime type with input [" + conn.getContentType() + "], defaulting to " + DEFAULT_MIMETYPE.toString()); } return new BinaryContentImpl(conn.getInputStream(), mimeType); }
From source file:org.unitedinternet.cosmo.dav.impl.StandardDavRequest.java
/** * //from w w w.j a v a 2 s . com * @param s mimeType as String * @return MimeType */ private static final MimeType registerMimeType(String s) { try { return new MimeType(s); } catch (MimeTypeParseException e) { throw new RuntimeException("Can't register MIME type " + s, e); } }