public static String getMimeType(ServletContext sc,String filename){ String mimeType = sc.getMimeType(filename); if(Strings.isEmpty(mimeType)){ mimeType = MimeTypes.getMimeType(filename); } return mimeType; }
@Override public MimeType getContentType() { if(null == contentType){ HttpEntity entity = response.getEntity(); Header header = null == entity ? null : entity.getContentType(); if(null != header){ contentType = MimeTypes.parse(header.getValue()); } } return contentType; }
@Override public THttpMultipart addFile(String name, String text, String filename, String contentType) { Args.notEmpty(filename, "filename"); if(null == contentType) { contentType = MimeTypes.getMimeType(filename); if(null == contentType) { contentType = "text/plain"; } } MediaType mediaType = MediaType.parse(MimeTypes.parse(contentType).withCharset(charset.name()).toString()); byte[] data = null == text ? new byte[]{} : text.getBytes(charset); mp.addFormDataPart(name, filename, RequestBody.create(mediaType, data)); empty = false; return this; } }
@Override public MimeType getContentType(){ if(null == contentType){ HttpEntity entity = httpResponse.getEntity(); Header header = null == entity ? null : entity.getContentType(); if(null != header){ contentType = MimeTypes.parse(header.getValue()); } } return contentType; }
@Override public THttpMultipart addFile(String name, byte[] data, String filename, String contentType) { Args.notEmpty(filename, "filename"); if(null == contentType) { contentType = MimeTypes.getMimeType(filename); } addBinaryPart(name, data, contentType, filename); empty = false; return this; }
@Override public MimeType getContentType() { return null == body.contentType() ? null : MimeTypes.parse(body.contentType().toString()); }
@Override public THttpMultipart addFile(String name, String text, String filename, String contentType) { Args.notEmpty(filename, "filename"); ContentType contentTypeObject = null; if(null == contentType) { contentType = MimeTypes.getMimeType(filename); if(null != contentType) { contentTypeObject = ContentType.create(contentType, charset); } }else{ contentTypeObject = ContentType.create(contentType); } if(null == contentTypeObject) { contentTypeObject = ContentType.create("text/plain",charset.name()); } byte[] data = null == text ? new byte[]{} : text.getBytes(charset); mp.addBinaryBody(name, data, contentTypeObject, filename); empty = false; return this; }
/** * Parse the given, comma-separated string into a list of {@code MimeType} objects. * @param mimeTypes the string to parse * @return the list of mime types * @throws IllegalArgumentException if the string cannot be parsed */ public static List<MimeType> parseList(String mimeTypes) { if (Strings.isEmpty(mimeTypes)) { return Collections.emptyList(); } String[] tokens = mimeTypes.split(",\\s*"); List<MimeType> result = new ArrayList<MimeType>(tokens.length); for (String token : tokens) { result.add(parse(token)); } return result; }
@Override public MimeType getContentType() { if(null == contentType) { String header = getHeader(Headers.CONTENT_TYPE); if(!Strings.isEmpty(header)) { contentType = MimeTypes.parse(header); } } return contentType; }