use of org.apache.james.mime4j.dom.BinaryBody in project sling by apache.
the class MessageStoreImplAttachmentsTest method createRandomBinaryAttachment.
/*
* taken from http://svn.apache.org/repos/asf/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
*/
private static BodyPart createRandomBinaryAttachment(int numberOfBytes) throws IOException {
byte[] data = new byte[numberOfBytes];
new Random().nextBytes(data);
Body body = new StorageBodyFactory().binaryBody(new ByteArrayInputStream(data));
BodyPart bodyPart = new BodyPart();
bodyPart.setContentDisposition("attachment", "file" + Math.random());
bodyPart.setBody(body, "application/octet-stream");
return bodyPart;
}
use of org.apache.james.mime4j.dom.BinaryBody in project Gargoyle by callakrsos.
the class MimeToHtmlWordAdapter method append.
/***************************************************************************/
/* sb에 번역된 텍스트데이터를 덧붙임 */
/***************************************************************************/
private void append(StringBuilder sb, Body body) {
if (body instanceof TextBody) {
/*
* A text body. Display its contents.
*/
TextBody textBody = (TextBody) body;
try {
Reader r = textBody.getReader();
int c;
while ((c = r.read()) != -1) {
sb.append((char) c);
}
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (body instanceof BinaryBody) {
BinaryBody bBody = (BinaryBody) body;
append(sb, bBody);
} else if (body instanceof Multipart) {
Multipart mbody = (Multipart) body;
for (Entity part : mbody.getBodyParts()) {
append(sb, part);
}
} else /*
* Ignore Fields </br>
*
* ContentTypeField,AddressListField,DateTimeField UnstructuredField,
* Field
*
*/
{
sb.append(body.toString());
}
}
use of org.apache.james.mime4j.dom.BinaryBody in project Gargoyle by callakrsos.
the class MimeViewerExam method extracted.
private void extracted(StringBuilder sb, Body body) {
if (body instanceof Multipart) {
Multipart mbody = (Multipart) body;
for (Entity part : mbody.getBodyParts()) {
extracted(sb, part);
}
} else if (body instanceof MessageImpl) {
extracted(sb, body);
} else if (body instanceof TextBody) {
/*
* A text body. Display its contents.
*/
TextBody textBody = (TextBody) body;
try {
Reader r = textBody.getReader();
StringBuilder _sb = new StringBuilder();
int c;
while ((c = r.read()) != -1) {
_sb.append((char) c);
}
System.out.println(_sb.toString());
sb.append(_sb.toString());
} catch (IOException ex) {
ex.printStackTrace();
}
} else if (body instanceof BinaryBody) {
BinaryBody bBody = (BinaryBody) body;
Entity parent = bBody.getParent();
// String dispositionType = parent.getDispositionType();
// String filename = parent.getFilename();
// String contentTransferEncoding = parent.getContentTransferEncoding();
// String mimeType = parent.getMimeType();
Field field = parent.getHeader().getField("Content-ID");
String body2 = field.getBody();
String contentId = body2.replace("<", "").replace(">", "");
StringBuffer buf = new StringBuffer();
try (InputStream is = bBody.getInputStream()) {
int read = -1;
while ((read = is.read()) != -1) {
buf.append((char) read);
}
} catch (IOException e) {
e.printStackTrace();
}
meta.put(contentId, buf.toString());
} else /*
* Ignore Fields </br>
*
* ContentTypeField,AddressListField,DateTimeField UnstructuredField,
* Field
*
*/
{
sb.append(body.toString());
}
}
Aggregations