本文整理汇总了Java中org.apache.james.mime4j.message.Body类的典型用法代码示例。如果您正苦于以下问题:Java Body类的具体用法?Java Body怎么用?Java Body使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Body类属于org.apache.james.mime4j.message包,在下文中一共展示了Body类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInputStream
import org.apache.james.mime4j.message.Body; //导入依赖的package包/类
@Override
public InputStream getInputStream() throws IOException {
Body body = bodyPart.getBody();
InputStream result = null;
if (body instanceof TextBody) {
throw new UnsupportedOperationException();
/*
* InputStreamReader reader = (InputStreamReader)((TextBody)
* body).getReader(); StringBuilder inputBuilder = new
* StringBuilder(); char[] buffer = new char[1024]; while (true)
* { int readCount = reader.read(buffer); if (readCount < 0) {
* break; } inputBuilder.append(buffer, 0, readCount); } String
* str = inputBuilder.toString(); return new
* ByteArrayInputStream(str.getBytes(reader.getEncoding()));
*/
} else if (body instanceof BinaryBody) {
return ((BinaryBody) body).getInputStream();
}
return result;
}
示例2: getTotalLength
import org.apache.james.mime4j.message.Body; //导入依赖的package包/类
/**
* Determines the total length of the multipart content (content length of
* individual parts plus that of extra elements required to delimit the parts
* from one another). If any of the @{link BodyPart}s contained in this object
* is of a streaming entity of unknown length the total length is also unknown.
* <p/>
* This method buffers only a small amount of data in order to determine the
* total length of the entire entity. The content of individual parts is not
* buffered.
*
* @return total length of the multipart entity if known, <code>-1</code>
* otherwise.
*/
public long getTotalLength() {
List<?> bodyParts = getBodyParts();
long contentLen = 0;
for (int i = 0; i < bodyParts.size(); i++) {
BodyPart part = (BodyPart) bodyParts.get(i);
Body body = part.getBody();
if (body instanceof ContentBody) {
long len = ((ContentBody) body).getContentLength();
if (len >= 0) {
contentLen += len;
} else {
return -1;
}
} else {
return -1;
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
doWriteTo(this.mode, out, false);
byte[] extra = out.toByteArray();
return contentLen + extra.length;
} catch (IOException ex) {
// Should never happen
return -1;
}
}