当前位置: 首页>>代码示例>>Java>>正文


Java Body类代码示例

本文整理汇总了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;
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:21,代码来源:MultipartInputImpl.java

示例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;
    }
}
 
开发者ID:appcelerator-archive,项目名称:ti.box,代码行数:43,代码来源:HttpMultipart.java


注:本文中的org.apache.james.mime4j.message.Body类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。