private static BasicContent fromStream(InputStream in, ContentType contentType) throws IOException {
		if (in == null) {
			throw new NullPointerException("input stream is null");
		}
		BasicContent result;
		if (contentType.isMultipart()) {
			MIMEConfig mimeConfig = new MIMEConfig();
			MIMEMessage msg = new MIMEMessage(in, contentType.getParameter("boundary"), mimeConfig);
			List<Content> contents = new ArrayList<Content>();
			for (MIMEPart part : msg.getAttachments()) {
				BasicContent content;
				ContentType partType = new ContentType(part.getContentType());
				if (partType.isMultipart()) {
					content = fromStream(part.readOnce(), partType);
					part.close();
				} else {
					content = fromPart(part, partType);
					part.close();
				}
				content.setContentId(part.getContentId());
				content.setContentLocation(getContentLocation(part));
				content.setContentType(part.getContentType());
				contents.add(content);
			}
			result = new BasicContent(contents);
		} else if (contentType.getMimeTypeWithoutParams().equals("text/xml")) {
			result = new SoapContent(in);
		} else if (contentType.getPrimaryType().equals("text")) {
			TextContent text = new TextContent();
			String encoding = new ContentType(contentType).getParameter("charset");
			if (encoding == null) {
				encoding = "iso-8859-1";
			}
			text.setText(new String(BinaryContent.toByteArray(in, 1024, 256 * 1024), encoding));
			result = text;
		} else {
			result = new BinaryContent(contentType.getMimeType(), in);
		}
		result.setContentType(contentType.getMimeType());
		return result;
	}