当前位置: 首页>>代码示例>>Java>>正文


Java DataSource.getContentType方法代码示例

本文整理汇总了Java中javax.activation.DataSource.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Java DataSource.getContentType方法的具体用法?Java DataSource.getContentType怎么用?Java DataSource.getContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.activation.DataSource的用法示例。


在下文中一共展示了DataSource.getContentType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContent

import javax.activation.DataSource; //导入方法依赖的package包/类
/**
 * Create an object from the input stream
 */
public Object getContent(DataSource ds) throws IOException {
    String ctStr = ds.getContentType();
    String charset = null;
    if (ctStr != null) {
        ContentType ct = new ContentType(ctStr);
        if (!isXml(ct)) {
            throw new IOException(
                "Cannot convert DataSource with content type \""
                        + ctStr + "\" to object in XmlDataContentHandler");
        }
        charset = ct.getParameter("charset");
    }
    return (charset != null)
            ? new StreamSource(new InputStreamReader(ds.getInputStream()), charset)
            : new StreamSource(ds.getInputStream());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:XmlDataContentHandler.java

示例2: encode

import javax.activation.DataSource; //导入方法依赖的package包/类
private ContentType encode(MessageDataSource mds, OutputStream out) {
    try {
        final boolean isFastInfoset = XMLMessage.isFastInfoset(
                mds.getDataSource().getContentType());
        DataSource ds = transformDataSource(mds.getDataSource(),
                isFastInfoset, useFastInfosetForEncoding, features);

        InputStream is = ds.getInputStream();
        byte[] buf = new byte[1024];
        int count;
        while((count=is.read(buf)) != -1) {
            out.write(buf, 0, count);
        }
        return new ContentTypeImpl(ds.getContentType());
    } catch(IOException ioe) {
        throw new WebServiceException(ioe);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:XMLHTTPBindingCodec.java

示例3: MimePullMultipart

import javax.activation.DataSource; //导入方法依赖的package包/类
public MimePullMultipart(DataSource ds, ContentType ct)
    throws MessagingException {
    parsed = false;
    if (ct==null)
        contType = new ContentType(ds.getContentType());
    else
        contType = ct;

    dataSource = ds;
    boundary = contType.getParameter("boundary");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:MimePullMultipart.java

示例4: getEncoding

import javax.activation.DataSource; //导入方法依赖的package包/类
/**
 * Get the content-transfer-encoding that should be applied
 * to the input stream of this datasource, to make it mailsafe. <p>
 *
 * The algorithm used here is: <br>
 * <ul>
 * <li>
 * If the primary type of this datasource is "text" and if all
 * the bytes in its input stream are US-ASCII, then the encoding
 * is "7bit". If more than half of the bytes are non-US-ASCII, then
 * the encoding is "base64". If less than half of the bytes are
 * non-US-ASCII, then the encoding is "quoted-printable".
 * <li>
 * If the primary type of this datasource is not "text", then if
 * all the bytes of its input stream are US-ASCII, the encoding
 * is "7bit". If there is even one non-US-ASCII character, the
 * encoding is "base64".
 * </ul>
 *
 * @param   ds      DataSource
 * @return          the encoding. This is either "7bit",
 *                  "quoted-printable" or "base64"
 */
public static String getEncoding(DataSource ds) {
    ContentType cType = null;
    InputStream is = null;
    String encoding = null;

    try {
        cType = new ContentType(ds.getContentType());
        is = ds.getInputStream();
    } catch (Exception ex) {
        return "base64"; // what else ?!
    }

    boolean isText = cType.match("text/*");
    // if not text, stop processing when we see non-ASCII
    int i = checkAscii(is, ALL, !isText);
    switch (i) {
    case ALL_ASCII:
        encoding = "7bit"; // all ascii
        break;
    case MOSTLY_ASCII:
        encoding = "quoted-printable"; // mostly ascii
        break;
    default:
        encoding = "base64"; // mostly binary
        break;
    }

    // Close the input stream
    try {
        is.close();
    } catch (IOException ioex) { }

    return encoding;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:58,代码来源:MimeUtility.java

示例5: DataSourceSource

import javax.activation.DataSource; //导入方法依赖的package包/类
public DataSourceSource(DataSource source) throws MimeTypeParseException {
    this.source = source;

    String ct = source.getContentType();
    if(ct==null) {
        charset = null;
    } else {
        MimeType mimeType = new MimeType(ct);
        this.charset = mimeType.getParameter("charset");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:DataSourceSource.java

示例6: MimeMultipart

import javax.activation.DataSource; //导入方法依赖的package包/类
/**
 * Constructs a MimeMultipart object and its bodyparts from the
 * given DataSource. <p>
 *
 * This constructor handles as a special case the situation where the
 * given DataSource is a MultipartDataSource object.
 *
 * Otherwise, the DataSource is assumed to provide a MIME multipart
 * byte stream.  The <code>parsed</code> flag is set to false.  When
 * the data for the body parts are needed, the parser extracts the
 * "boundary" parameter from the content type of this DataSource,
 * skips the 'preamble' and reads bytes till the terminating
 * boundary and creates MimeBodyParts for each part of the stream.
 *
 * @param   ds      DataSource, can be a MultipartDataSource
 * @param ct
 *      This must be the same information as {@link DataSource#getContentType()}.
 *      All the callers of this method seem to have this object handy, so
 *      for performance reason this method accepts it. Can be null.
 */
public MimeMultipart(DataSource ds, ContentType ct) throws MessagingException {
    // 'ds' was not a MultipartDataSource, we have
    // to parse this ourself.
    parsed = false;
    this.ds = ds;
    if (ct==null)
        contentType = new ContentType(ds.getContentType());
    else
        contentType = ct;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:MimeMultipart.java

示例7: MimeMultipart

import javax.activation.DataSource; //导入方法依赖的package包/类
/**
 * Constructs a MimeMultipart object and its bodyparts from the
 * given DataSource. <p>
 *
 * This constructor handles as a special case the situation where the
 * given DataSource is a MultipartDataSource object.
 *
 * Otherwise, the DataSource is assumed to provide a MIME multipart
 * byte stream.  The <code>parsed</code> flag is set to false.  When
 * the data for the body parts are needed, the parser extracts the
 * "boundary" parameter from the content type of this DataSource,
 * skips the 'preamble' and reads bytes till the terminating
 * boundary and creates MimeBodyParts for each part of the stream.
 *
 * @param   ds      DataSource, can be a MultipartDataSource
 * @param ct
 *      This must be the same information as {@link DataSource#getContentType()}.
 *      All the callers of this method seem to have this object handy, so
 *      for performance reason this method accepts it. Can be null.
 *
 * @exception MessagingException in case of error
 */
public MimeMultipart(DataSource ds, ContentType ct) throws MessagingException {
    // 'ds' was not a MultipartDataSource, we have
    // to parse this ourself.
    parsed = false;
    this.ds = ds;
    if (ct==null)
        contentType = new ContentType(ds.getContentType());
    else
        contentType = ct;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:MimeMultipart.java


注:本文中的javax.activation.DataSource.getContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。