/** * Creates a new instance of {@link ContentType} without a charset. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @return content type */ public static ContentType create(final String mimeType) { return new ContentType(mimeType, (Charset) null); }
/** * Creates a new instance of {@link ContentType} without a charset. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @return content type */ public static ContentType create(final String mimeType) { return new ContentType(mimeType, (Charset) null); }
/** * Creates a new instance of {@link ContentType} without a charset. * * @param mimeType MIME type. It may not be <code>null</code> or empty. It may not contain * characters <">, <;>, <,> reserved by the HTTP specification. * @return content type */ public static ContentType create(final String mimeType) { return new ContentType(mimeType, (Charset) null); }
/** * Creates a new instance of {@link ContentType} without a charset. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @return content type */ public static ContentType create(final String mimeType) { return new ContentType(mimeType, (Charset) null); }
/** * Creates a new instance of {@link ContentType} without a charset. * * @param mimeType MIME type. It may not be <code>null</code> or empty. It may not contain * characters <">, <;>, <,> reserved by the HTTP specification. * @return content type */ public static ContentType create(final String mimeType) { return new ContentType(mimeType, (Charset) null); }
private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) { Charset charset = null; for (final NameValuePair param: params) { if (param.getName().equalsIgnoreCase("charset")) { final String s = param.getValue(); if (!TextUtils.isBlank(s)) { try { charset = Charset.forName(s); } catch (UnsupportedCharsetException ex) { if (strict) { throw ex; } } } break; } } return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null); }
private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) { Charset charset = null; for (final NameValuePair param: params) { if (param.getName().equalsIgnoreCase("charset")) { final String s = param.getValue(); if (!TextUtils.isBlank(s)) { try { charset = Charset.forName(s); } catch (final UnsupportedCharsetException ex) { if (strict) { throw ex; } } } break; } } return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null); }
private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) { Charset charset = null; for (final NameValuePair param: params) { if (param.getName().equalsIgnoreCase("charset")) { final String s = param.getValue(); if (!TextUtils.isBlank(s)) { try { charset = Charset.forName(s); } catch (UnsupportedCharsetException ex) { if (strict) { throw ex; } } } break; } } return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null); }
private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) { Charset charset = null; for (final NameValuePair param: params) { if (param.getName().equalsIgnoreCase("charset")) { final String s = param.getValue(); if (!TextUtils.isBlank(s)) { try { charset = Charset.forName(s); } catch (UnsupportedCharsetException ex) { if (strict) { throw ex; } } } break; } } return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null); }
public static String cleanContentType(MimePart mp, String contentType) { String ct = "TEXT/PLAIN; charset=\"=?utf-8?B?ICJVVEYtOCI=?=\""; ContentType content = new ContentType(ct); System.out.println(content.getBaseType()); System.out.println(content.getParameter("charset")); System.out.println(MimeUtility.decodeText(content.getParameter("charset"))); }
private static ContentType create(final HeaderElement helem) { final String mimeType = helem.getName(); final NameValuePair[] params = helem.getParameters(); return new ContentType(mimeType, params != null && params.length > 0 ? params : null); }
private static ContentType create(final HeaderElement helem) { final String mimeType = helem.getName(); final NameValuePair[] params = helem.getParameters(); return new ContentType(mimeType, params != null && params.length > 0 ? params : null); }
public static String cleanContentType(MimePart mp, String contentType) { try { ContentType content = new ContentType(contentType); String charset = MimeUtility.decodeText(content.getParameter("charset")); charset = charset.replace("\"", ""); content.setParameter("charset", charset); return content.toString(); } catch (MessagingException | UnsupportedEncodingException ex) { return contentType; } }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(type), "MIME type may not contain reserved characters"); return new ContentType(type, charset); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(type), "MIME type may not contain reserved characters"); return new ContentType(type, charset); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(type), "MIME type may not contain reserved characters"); return new ContentType(type, charset); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be <code>null</code> or empty. It may not contain * characters <">, <;>, <,> reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.US); Args.check(valid(type), "MIME type may not contain reserved characters"); return new ContentType(type, charset); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be <code>null</code> or empty. It may not contain * characters <">, <;>, <,> reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ENGLISH); Args.check(valid(type), "MIME type may not contain reserved characters"); return new ContentType(type, charset); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String normalizedMimeType = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(normalizedMimeType), "MIME type may not contain reserved characters"); return new ContentType(normalizedMimeType, charset); }
public class MergeDocx { private static long chunk = 0; private static final String CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; public void mergeDocx(InputStream s1, InputStream s2, OutputStream os) throws Exception { WordprocessingMLPackage target = WordprocessingMLPackage.load(s1); insertDocx(target.getMainDocumentPart(), IOUtils.toByteArray(s2)); SaveToZipFile saver = new SaveToZipFile(target); saver.save(os); } private static void insertDocx(MainDocumentPart main, byte[] bytes) throws Exception { AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/part" + (chunk++) + ".docx")); afiPart.setContentType(new ContentType(CONTENT_TYPE)); afiPart.setBinaryData(bytes); Relationship altChunkRel = main.addTargetPart(afiPart); CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk(); chunk.setId(altChunkRel.getId()); main.addObject(chunk); } }