當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSource.getInputStream方法代碼示例

本文整理匯總了Java中javax.activation.DataSource.getInputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSource.getInputStream方法的具體用法?Java DataSource.getInputStream怎麽用?Java DataSource.getInputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.activation.DataSource的用法示例。


在下文中一共展示了DataSource.getInputStream方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: findAvatarInputStream

import javax.activation.DataSource; //導入方法依賴的package包/類
public InputStream findAvatarInputStream(String userId) {
    try {
        Long accountId = Long.parseLong(userId);
        DataSource dataSource = userAvatarService.viewAvatarById(accountId,
                35, "1");

        return dataSource.getInputStream();
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }

    return null;
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:14,代碼來源:AvatarConnectorImpl.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


注:本文中的javax.activation.DataSource.getInputStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。