Copy to ClipboardCopied!Toggle word wrapToggle overflow
이메일을 기록하는 대신 Java 코드에서 우편을 처리할 수 있는 프로세서를 사용합니다.
public void process(Exchange exchange) throws Exception {
// the API is a bit clunky so we need to loop
AttachmentMessage attachmentMessage = exchange.getMessage(AttachmentMessage.class);
Map<String, DataHandler> attachments = attachmentMessage.getAttachments();
if (attachments.size() > 0) {
for (String name : attachments.keySet()) {
DataHandler dh = attachments.get(name);
// get the file name
String filename = dh.getName();
// get the content and convert it to byte[]
byte[] data = exchange.getContext().getTypeConverter()
.convertTo(byte[].class, dh.getInputStream());
// write the data to a file
FileOutputStream out = new FileOutputStream(filename);
out.write(data);
out.flush();
out.close();
}
}
}
public void process(Exchange exchange) throws Exception {
// the API is a bit clunky so we need to loop
AttachmentMessage attachmentMessage = exchange.getMessage(AttachmentMessage.class);
Map<String, DataHandler> attachments = attachmentMessage.getAttachments();
if (attachments.size() > 0) {
for (String name : attachments.keySet()) {
DataHandler dh = attachments.get(name);
// get the file name
String filename = dh.getName();
// get the content and convert it to byte[]
byte[] data = exchange.getContext().getTypeConverter()
.convertTo(byte[].class, dh.getInputStream());
// write the data to a file
FileOutputStream out = new FileOutputStream(filename);
out.write(data);
out.flush();
out.close();
}
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
첨부 파일을 처리하는 API를 볼 수 있듯이 약간의 문제가 발생하지만, 표준 API를 사용하여 첨부 파일을 처리할 수 있도록 javax.activation.DataHandler 를 얻을 수 있습니다.