本文整理匯總了Java中javax.activation.DataSource類的典型用法代碼示例。如果您正苦於以下問題:Java DataSource類的具體用法?Java DataSource怎麽用?Java DataSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataSource類屬於javax.activation包,在下文中一共展示了DataSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setAttachment
import javax.activation.DataSource; //導入依賴的package包/類
public static void setAttachment(Message message, String filename) throws MessagingException {
// Create a multipar message
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
//Set File
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
//Add "file part" to multipart
multipart.addBodyPart(messageBodyPart);
//Set multipart to message
message.setContent(multipart);
}
示例2: viewAvatarById
import javax.activation.DataSource; //導入依賴的package包/類
public DataSource viewAvatarById(Long accountId, int width, String tenantId)
throws Exception {
if (accountId == null) {
logger.info("accountId cannot be null");
return null;
}
String key = "accountId:" + accountId + ":" + width;
String userId = Long.toString(accountId);
DataSource dataSource = this.avatarCache.getDataSource(userId, width);
if (dataSource != null) {
return dataSource;
}
AccountInfo accountInfo = accountInfoManager.get(accountId);
dataSource = this.viewAvatarByAccountInfo(accountInfo, width, tenantId);
this.avatarCache.updateDataSource(userId, width, dataSource);
return dataSource;
}
示例3: viewAvatarByUsername
import javax.activation.DataSource; //導入依賴的package包/類
public DataSource viewAvatarByUsername(String username, int width,
String tenantId) throws Exception {
// String key = "username:" + username + ":" + width;
AccountInfo accountInfo = accountInfoManager.findUniqueBy("username",
username);
String userId = Long.toString(accountInfo.getId());
DataSource dataSource = this.avatarCache.getDataSource(userId, width);
if (dataSource != null) {
return dataSource;
}
dataSource = this.viewAvatarByAccountInfo(accountInfo, width, tenantId);
this.avatarCache.updateDataSource(userId, width, dataSource);
return dataSource;
}
示例4: updateDataSource
import javax.activation.DataSource; //導入依賴的package包/類
public void updateDataSource(String userId, int width, DataSource dataSource) {
try {
String key = userId + ":" + width;
byte[] bytes = IOUtils.toByteArray(dataSource.getInputStream());
Set<String> aliasValue = this.aliasCache.get(userId);
if (aliasValue == null) {
aliasValue = new HashSet<String>();
this.aliasCache.put(userId, aliasValue);
}
aliasValue.add(key);
this.dataCache.put(key, bytes);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
示例5: saveStore
import javax.activation.DataSource; //導入依賴的package包/類
public StoreDTO saveStore(InputStream inputStream, String fileName,
String contentType, String tenantId) throws Exception {
int len = -1;
byte[] b = new byte[1024];
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
while ((len = inputStream.read(b, 0, 1024)) != -1) {
baos2.write(b, 0, len);
}
inputStream.close();
byte[] bytes = baos2.toByteArray();
DataSource dataSource = new ByteArrayDataSource(fileName, bytes);
StoreDTO storeDto = storeService.saveStore(model, dataSource, tenantId);
return storeDto;
}
示例6: saveStore
import javax.activation.DataSource; //導入依賴的package包/類
public StoreResult saveStore(String model, String key, DataSource dataSource)
throws Exception {
String path = key;
File dir = new File(baseDir + "/" + model);
dir.mkdirs();
File targetFile = new File(baseDir + "/" + model + "/" + path);
FileOutputStream fos = new FileOutputStream(targetFile);
try {
FileCopyUtils.copy(dataSource.getInputStream(), fos);
fos.flush();
} finally {
fos.close();
}
StoreResult storeResult = new StoreResult();
storeResult.setModel(model);
storeResult.setKey(path);
storeResult.setDataSource(new FileDataSource(targetFile));
return storeResult;
}
示例7: createDataSource
import javax.activation.DataSource; //導入依賴的package包/類
/**
* Create an Activation Framework DataSource for the given InputStreamSource.
* @param inputStreamSource the InputStreamSource (typically a Spring Resource)
* @param contentType the content type
* @param name the name of the DataSource
* @return the Activation Framework DataSource
*/
protected DataSource createDataSource(
final InputStreamSource inputStreamSource, final String contentType, final String name) {
return new DataSource() {
@Override
public InputStream getInputStream() throws IOException {
return inputStreamSource.getInputStream();
}
@Override
public OutputStream getOutputStream() {
throw new UnsupportedOperationException("Read-only javax.activation.DataSource");
}
@Override
public String getContentType() {
return contentType;
}
@Override
public String getName() {
return name;
}
};
}
示例8: addAttachment
import javax.activation.DataSource; //導入依賴的package包/類
public void addAttachment(final FormFile file) throws Exception {
addAttachment(file.getFileName(),
new DataHandler(new DataSource() {
@Override
public OutputStream getOutputStream() throws IOException {
throw new IOException("No output stream.");
}
@Override
public String getName() {
return file.getFileName();
}
@Override
public InputStream getInputStream() throws IOException {
return file.getInputStream();
}
@Override
public String getContentType() {
return file.getContentType();
}
}));
}
示例9: eventUpdated
import javax.activation.DataSource; //導入依賴的package包/類
public static void eventUpdated(Event updatedEvent, String message, InternetAddress replyTo, DataSource attachment) throws Exception {
if (ApplicationProperty.EmailConfirmationEvents.isFalse())
return;
Session session = updatedEvent.getSession();
if (session == null)
for (Meeting m: updatedEvent.getMeetings())
if (m.getLocation() != null) { session = m.getLocation().getSession(); break; }
EventInterface event = EventDetailBackend.getEventDetail(session, updatedEvent, null);
ApproveEventRpcRequest request = new ApproveEventRpcRequest();
request.setOperation(SaveOrApproveEventRpcRequest.Operation.UPDATE);
if (message != null && !message.isEmpty())
request.setMessage(message);
request.setEmailConfirmation(true);
request.setSessionId(session == null ? null : session.getUniqueId());
request.setEvent(event);
SaveOrApproveEventRpcResponse response = new SaveOrApproveEventRpcResponse();
response.setEvent(event);
new EventEmail(request, response, attachment, replyTo).send(null);
}
示例10: createDispatch
import javax.activation.DataSource; //導入依賴的package包/類
/**
* Creates a new {@link Dispatch} stub that connects to the given pipe.
*
* @param portInfo
* see <a href="#param">common parameters</a>
* @param owner
* see <a href="#param">common parameters</a>
* @param binding
* see <a href="#param">common parameters</a>
* @param clazz
* Type of the {@link Dispatch} to be created.
* See {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param mode
* The mode of the dispatch.
* See {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param epr
* see <a href="#param">common parameters</a>
* TODO: are these parameters making sense?
*/
public static <T> Dispatch<T> createDispatch(WSPortInfo portInfo,
WSService owner,
WSBinding binding,
Class<T> clazz, Service.Mode mode,
@Nullable WSEndpointReference epr) {
if (clazz == SOAPMessage.class) {
return (Dispatch<T>) createSAAJDispatch(portInfo, binding, mode, epr);
} else if (clazz == Source.class) {
return (Dispatch<T>) createSourceDispatch(portInfo, binding, mode, epr);
} else if (clazz == DataSource.class) {
return (Dispatch<T>) createDataSourceDispatch(portInfo, binding, mode, epr);
} else if (clazz == Message.class) {
if(mode==Mode.MESSAGE)
return (Dispatch<T>) createMessageDispatch(portInfo, binding, epr);
else
throw new WebServiceException(mode+" not supported with Dispatch<Message>");
} else if (clazz == Packet.class) {
if(mode==Mode.MESSAGE)
return (Dispatch<T>) createPacketDispatch(portInfo, binding, epr);
else
throw new WebServiceException(mode+" not supported with Dispatch<Packet>");
} else
throw new WebServiceException("Unknown class type " + clazz.getName());
}
示例11: BMMimeMultipart
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. In this case, this
* method just invokes the superclass (i.e., Multipart) constructor
* that takes a MultipartDataSource object. <p>
*
* 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 ct content type.
* @param ds DataSource, can be a MultipartDataSource.
* @throws MessagingException in case of error.
*/
public BMMimeMultipart(DataSource ds, ContentType ct)
throws MessagingException {
super(ds, ct);
boundary = ct.getParameter("boundary");
/*
if (ds instanceof MultipartDataSource) {
// ask super to do this for us.
setMultipartDataSource((MultipartDataSource)ds);
return;
}
// '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;
*/
}
示例12: 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);
}
}
示例13: getDataHandler
import javax.activation.DataSource; //導入依賴的package包/類
DataHandler getDataHandler() {
DataSource ds = new DataSource() {
public OutputStream getOutputStream() throws IOException {
throw new IOException("Illegal Operation");
}
public String getContentType() {
return getContentTypeString();
}
public String getName() {
return getContentId();
}
public InputStream getInputStream() throws IOException {
return getContentAsStream();
}
};
return new DataHandler(ds);
}
示例14: createDispatch
import javax.activation.DataSource; //導入依賴的package包/類
/**
* Creates a new {@link Dispatch} stub that connects to the given pipe.
*
* @param portName
* see {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param owner
* see <a href="#param">common parameters</a>
* @param binding
* see <a href="#param">common parameters</a>
* @param clazz
* Type of the {@link Dispatch} to be created.
* See {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param mode
* The mode of the dispatch.
* See {@link Service#createDispatch(QName, Class, Service.Mode)}.
* @param next
* see <a href="#param">common parameters</a>
* @param epr
* see <a href="#param">common parameters</a>
* TODO: are these parameters making sense?
*/
@SuppressWarnings("unchecked")
public static <T> Dispatch<T> createDispatch(QName portName,
WSService owner,
WSBinding binding,
Class<T> clazz, Service.Mode mode, Tube next,
@Nullable WSEndpointReference epr) {
if (clazz == SOAPMessage.class) {
return (Dispatch<T>) createSAAJDispatch(portName, owner, binding, mode, next, epr);
} else if (clazz == Source.class) {
return (Dispatch<T>) createSourceDispatch(portName, owner, binding, mode, next, epr);
} else if (clazz == DataSource.class) {
return (Dispatch<T>) createDataSourceDispatch(portName, owner, binding, mode, next, epr);
} else if (clazz == Message.class) {
if(mode==Mode.MESSAGE)
return (Dispatch<T>) createMessageDispatch(portName, owner, binding, next, epr);
else
throw new WebServiceException(mode+" not supported with Dispatch<Message>");
} else if (clazz == Packet.class) {
return (Dispatch<T>) createPacketDispatch(portName, owner, binding, next, epr);
} else
throw new WebServiceException("Unknown class type " + clazz.getName());
}
示例15: 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;
}