本文整理了Java中javax.mail.internet.MimeMultipart.writeTo()
方法的一些代码示例,展示了MimeMultipart.writeTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMultipart.writeTo()
方法的具体详情如下:
包路径:javax.mail.internet.MimeMultipart
类名称:MimeMultipart
方法名:writeTo
[英]Iterates through all the parts and outputs each MIME part separated by a boundary.
[中]
代码示例来源:origin: voldemort/voldemort
message.saveChanges();
try {
multiPartKeys.writeTo(keysOutputStream);
} catch(Exception e) {
logger.error("Exception while writing mutipart to output stream", e);
代码示例来源:origin: voldemort/voldemort
message.saveChanges();
try {
multiPart.writeTo(outputStream);
} catch(Exception e) {
logger.error("Exception while writing multipart to output stream", e);
代码示例来源:origin: geoserver/geoserver
public void testMultiPartFormUpload() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/geoserver");
request.setRequestURI("/geoserver/hello");
request.setMethod("post");
String xml = "<Hello service='hello' message='Hello world!' version='1.0.0' />";
MimeMultipart body = new MimeMultipart();
request.setContentType(body.getContentType());
InternetHeaders headers = new InternetHeaders();
headers.setHeader(
"Content-Disposition", "form-data; name=\"upload\"; filename=\"request.xml\"");
headers.setHeader("Content-Type", "application/xml");
body.addBodyPart(new MimeBodyPart(headers, xml.getBytes()));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
body.writeTo(bout);
request.setContent(bout.toByteArray());
MockHttpServletResponse response = new MockHttpServletResponse();
URL url = getClass().getResource("applicationContext.xml");
FileSystemXmlApplicationContext context =
new FileSystemXmlApplicationContext(url.toString());
Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");
dispatcher.handleRequestInternal(request, response);
assertEquals("Hello world!", response.getContentAsString());
}
代码示例来源:origin: geoserver/geoserver
public void testMultiPartFormUploadWithBodyField() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/geoserver");
request.setRequestURI("/geoserver/hello");
request.setMethod("post");
String xml = "<Hello service='hello' message='Hello world!' version='1.0.0' />";
MimeMultipart body = new MimeMultipart();
request.setContentType(body.getContentType());
InternetHeaders headers = new InternetHeaders();
headers.setHeader("Content-Disposition", "form-data; name=\"body\";");
headers.setHeader("Content-Type", "application/xml");
body.addBodyPart(new MimeBodyPart(headers, xml.getBytes()));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
body.writeTo(bout);
request.setContent(bout.toByteArray());
MockHttpServletResponse response = new MockHttpServletResponse();
URL url = getClass().getResource("applicationContext.xml");
FileSystemXmlApplicationContext context =
new FileSystemXmlApplicationContext(url.toString());
Dispatcher dispatcher = (Dispatcher) context.getBean("dispatcher");
dispatcher.handleRequestInternal(request, response);
assertEquals("Hello world!", response.getContentAsString());
}
代码示例来源:origin: resteasy/Resteasy
mimeMultipart.writeTo(entityStream);
代码示例来源:origin: resteasy/Resteasy
@Override
public void writeTo(SignedOutput out, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException
{
try
{
SMIMESignedGenerator gen = new SMIMESignedGenerator();
SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", out.getPrivateKey(), out.getCertificate());
gen.addSignerInfoGenerator(signer);
MimeMultipart mp = gen.generate(EnvelopedWriter.createBodyPart(providers, out));
String contentType = mp.getContentType();
contentType = contentType.replace("\r\n", "").replace("\t", " ");
headers.putSingle("Content-Type", contentType);
mp.writeTo(os);
}
catch (Exception e)
{
throw new WriterException(e);
}
}
}
代码示例来源:origin: org.mule.modules/mule-module-http
public static byte[] createMultipartContent(MultipartHttpEntity multipartEntity, String contentType) throws IOException, MessagingException
{
MimeMultipart mimeMultipartContent = HttpMultipartEncoder.createContent(multipartEntity, contentType);
final ByteArrayOutputStream byteArrayOutputStream;
byteArrayOutputStream = new ByteArrayOutputStream();
mimeMultipartContent.writeTo(byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
代码示例来源:origin: org.apache.geronimo.javamail/geronimo-javamail_1.4_provider
public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
if (obj instanceof MimeMultipart) {
MimeMultipart mp = (MimeMultipart) obj;
try {
mp.writeTo(os);
} catch (MessagingException e) {
throw (IOException) new IOException(e.getMessage()).initCause(e);
}
}
}
}
代码示例来源:origin: org.apache.axis/axis
public MimeMultipartDataSource(String name, MimeMultipart data) {
this.name = name;
this.contentType = data == null ? CONTENT_TYPE : data.getContentType();
os = new ByteArrayOutputStream();
try {
if (data != null) {
data.writeTo(os);
}
}
catch (Exception e) {
// Is this sufficient?
}
} // ctor
代码示例来源:origin: javax.mail/com.springsource.javax.mail
/**
* Write the object to the output stream, using the specific MIME type.
*/
public void writeTo(Object obj, String mimeType, OutputStream os)
throws IOException {
if (obj instanceof MimeMultipart) {
try {
((MimeMultipart)obj).writeTo(os);
} catch (MessagingException e) {
throw new IOException(e.toString());
}
}
}
}
代码示例来源:origin: org.mule.services/mule-service-http
public static byte[] toByteArray(HttpEntity multipartEntity, String contentType) throws IOException {
MimeMultipart mimeMultipartContent = HttpMultipartEncoder.toMimeMultipart(multipartEntity, contentType);
final ByteArrayOutputStream byteArrayOutputStream;
byteArrayOutputStream = new ByteArrayOutputStream();
try {
mimeMultipartContent.writeTo(byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (MessagingException e) {
throw new IOException(e);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax.mail
/**
* Write the object to the output stream, using the specific MIME type.
*/
public void writeTo(Object obj, String mimeType, OutputStream os)
throws IOException {
if (obj instanceof MimeMultipart) {
try {
((MimeMultipart)obj).writeTo(os);
} catch (MessagingException e) {
throw new IOException(e.toString());
}
}
}
}
代码示例来源:origin: axis/axis
public MimeMultipartDataSource(String name, MimeMultipart data) {
this.name = name;
this.contentType = data == null ? CONTENT_TYPE : data.getContentType();
os = new ByteArrayOutputStream();
try {
if (data != null) {
data.writeTo(os);
}
}
catch (Exception e) {
// Is this sufficient?
}
} // ctor
代码示例来源:origin: org.apache.axis/com.springsource.org.apache.axis
public MimeMultipartDataSource(String name, MimeMultipart data) {
this.name = name;
this.contentType = data == null ? CONTENT_TYPE : data.getContentType();
os = new ByteArrayOutputStream();
try {
if (data != null) {
data.writeTo(os);
}
}
catch (Exception e) {
// Is this sufficient?
}
} // ctor
代码示例来源:origin: com.ibm.sbt/com.ibm.sbt.core
public String payload(String atom) {
if (hasAttachments()) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MimeMultipart multipart = multipart(atom);
multipart.writeTo(baos);
return new String(baos.toByteArray());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else {
return atom;
}
}
代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec
/**
* Method writeTo
*
* @param object
* @param s
* @param outputstream
* @throws IOException
*/
public void writeTo(Object object, String s, OutputStream outputstream) throws IOException {
// if this object is a MimeMultipart, then delegate to the part.
if (object instanceof MimeMultipart) {
try {
((MimeMultipart)object).writeTo(outputstream);
} catch (MessagingException e) {
// we need to transform any exceptions into an IOException.
throw new IOException("Exception writing MimeMultipart: " + e.toString());
}
}
}
}
代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec
/**
* Method writeTo
*
* @param object
* @param s
* @param outputstream
* @throws IOException
*/
public void writeTo(Object object, String s, OutputStream outputstream) throws IOException {
// if this object is a MimeMultipart, then delegate to the part.
if (object instanceof MimeMultipart) {
try {
((MimeMultipart)object).writeTo(outputstream);
} catch (MessagingException e) {
// we need to transform any exceptions into an IOException.
throw new IOException("Exception writing MimeMultipart: " + e.toString());
}
}
}
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
public EncodedData getBytesFromMultipart(MimeMultipart value, Marshaller marshaller) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
ContentType contentType = new ContentType(value.getContentType());
String boundary = contentType.getParameter("boundary");
output.write(Constants.cr().getBytes());
output.write(("Content-Type: " + contentType.getBaseType() + "; boundary=\"" + boundary + "\"\n").getBytes());
} catch (Exception ex) {
throw ConversionException.couldNotBeConverted(value, byte[].class, ex);
}
try {
value.writeTo(output);
} catch (Exception ex) {
throw ConversionException.couldNotBeConverted(value, byte[].class, ex);
}
return new EncodedData(output.toByteArray(), value.getContentType());
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
public EncodedData getBytesFromMultipart(MimeMultipart value, Marshaller marshaller) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
ContentType contentType = new ContentType(value.getContentType());
String boundary = contentType.getParameter("boundary");
output.write(Constants.cr().getBytes());
output.write(("Content-Type: " + contentType.getBaseType() + "; boundary=\"" + boundary + "\"\n").getBytes());
} catch (Exception ex) {
throw ConversionException.couldNotBeConverted(value, byte[].class, ex);
}
try {
value.writeTo(output);
} catch (Exception ex) {
throw ConversionException.couldNotBeConverted(value, byte[].class, ex);
}
return new EncodedData(output.toByteArray(), value.getContentType());
}
代码示例来源:origin: stackoverflow.com
MimeBodyPart formPart = new MimeBodyPart();
formPart.setContent(
URLEncoder.encode(requestData.toString(), "UTF-8"),
"application/x-www-form-urlencoded");
formPart.setDisposition("form-data; name=\"form\"");
MimeBodyPart filePart = new MimeBodyPart();
filePart.attachFile(fileToUpload);
ContentDisposition disposition = new ContentDisposition("form-data");
disposition.getParameterList().set("name", "file");
disposition.getParameterList().set("filename", fileToUpload.toString(), "UTF-8");
filePart.setDisposition(disposition.toString());
MimeMultipart multipart = new MimeMultipart("form-data");
multipart.addBodyPart(formPart);
multipart.addBodyPart(filePart);
try (OutputStream out = con.getOutputStream()) {
multipart.writeTo(out);
}
内容来源于网络,如有侵权,请联系作者删除!