AttachmentService.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:jaffa-framework 作者:
/** Returns the contentType for the attachment.
 * The following algorithm is used
 *   - If the input is an array of bytes, then "application/x-download" is returned.
 *   - If the input is a String, then "text/plain" is returned.
 *   - If the input is a File, then a null is returned. The file name should be used to determine the contentType.
 *   - If the input carries the JAXB annotation, then "text/xml" is returned.
 *   - If none of the above are satisfied, then "text/xml" is returned.
 * @param attachment the attachment.
 * @throws FrameworkException If any system error occurs.
 * @throws ApplicationExceptions If any application error occurs.
 * @return the contentType for the attachment.
 */
public static String createContentType(Object attachment)
throws FrameworkException, ApplicationExceptions {
    String contentType = null;
    if (attachment.getClass().isArray() && attachment.getClass().getComponentType() == Byte.TYPE) {
        contentType = CONTENT_TYPE_BYTE_ARRAY;
    } else if (attachment instanceof String) {
        contentType = CONTENT_TYPE_STRING;
    } else if (attachment instanceof File) {
        // Do not set the contentType. It'll be determined based on the file name
    } else if (attachment.getClass().isAnnotationPresent(XmlRootElement.class)) {
        contentType = CONTENT_TYPE_JAXB;
    } else {
        contentType = CONTENT_TYPE_XML_ENCODER;
    }
    return contentType;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号