本文整理汇总了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());
}
示例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);
}
}
示例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;
}
示例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;
}