javax.activation.DataHandler.writeTo()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中javax.activation.DataHandler.writeTo()方法的一些代码示例,展示了DataHandler.writeTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataHandler.writeTo()方法的具体详情如下:
包路径:javax.activation.DataHandler
类名称:DataHandler
方法名:writeTo

DataHandler.writeTo介绍

[英]Write the data to an OutputStream.

If the DataHandler was created with a DataSource, writeTo retrieves the InputStream and copies the bytes from the InputStream to the OutputStream passed in.

If the DataHandler was created with an object, writeTo retrieves the DataContentHandler for the object's type. If the DataContentHandler was found, it calls the writeTo method on the DataContentHandler.
[中]将数据写入OutputStream
如果DataHandler是使用数据源创建的,writeTo将检索InputStream并将字节从InputStream复制到传入的OutputStream。
如果DataHandler是使用对象创建的,writeTo将检索对象类型的DataContentHandler。如果找到DataContentHandler,它将调用DataContentHandler上的writeTo方法。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

try {
  baos = new ByteArrayOutputStream();
  dh.writeTo(baos);
} catch (Exception e) {

代码示例来源:origin: camunda/camunda-bpm-platform

public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
 DataHandler dataHandler = mimeMessage.getDataHandler();
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 dataHandler.writeTo(baos);
 baos.flush();
 return baos.toString();
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
 DataHandler dataHandler = mimeMessage.getDataHandler();
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 dataHandler.writeTo(baos);
 baos.flush();
 return baos.toString();
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Output the body part as an RFC 822 format stream.
 *
 * @exception IOException    if an error occurs writing to the
 *                stream or if an error is generated
 *                by the javax.activation layer.
 * @exception MessagingException for other failures
 * @see javax.activation.DataHandler#writeTo
 */
public void writeTo(OutputStream os)
    throws IOException, MessagingException {
// see if we already have a LOS
LineOutputStream los = null;
if (os instanceof LineOutputStream) {
  los = (LineOutputStream) os;
} else {
  los = new LineOutputStream(os);
}
// First, write out the header
@SuppressWarnings("unchecked")
Enumeration<String> hdrLines = getAllHeaderLines();
while (hdrLines.hasMoreElements())
  los.writeln(hdrLines.nextElement());
// The CRLF separator between header and content
los.writeln();
// Finally, the content, already encoded.
getDataHandler().writeTo(os);
os.flush();
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Output the body part as an RFC 822 format stream.
 *
 * @exception IOException    if an error occurs writing to the
 *                stream or if an error is generated
 *                by the javax.activation layer.
 * @exception MessagingException for other failures
 * @see javax.activation.DataHandler#writeTo
 */
@Override
public void writeTo(OutputStream os)
    throws IOException, MessagingException {
// see if we already have a LOS
LineOutputStream los = null;
if (os instanceof LineOutputStream) {
  los = (LineOutputStream) os;
} else {
  los = new LineOutputStream(os);
}
// First, write out the header
Enumeration<String> hdrLines = getAllHeaderLines();
while (hdrLines.hasMoreElements())
  los.writeln(hdrLines.nextElement());
// The CRLF separator between header and content
los.writeln();
// Finally, the content, already encoded.
getDataHandler().writeTo(os);
os.flush();
}

代码示例来源:origin: camunda/camunda-bpm-platform

os = MimeUtility.encode(os,
  restrictEncoding(part, part.getEncoding()));
part.getDataHandler().writeTo(os);

代码示例来源:origin: com.sun.mail/javax.mail

os = MimeUtility.encode(os,
  restrictEncoding(part, part.getEncoding()));
part.getDataHandler().writeTo(os);

代码示例来源:origin: camunda/camunda-bpm-platform

dh.writeTo(aos);
} catch (IOException ex) {
  new AsciiOutputStream(true, encodeEolStrict);
try {
dh.writeTo(aos);
} catch (IOException ex) { }	// ignore it
if (aos.getAscii() == ALL_ASCII) // all ascii

代码示例来源:origin: com.sun.mail/javax.mail

dh.writeTo(aos);
} catch (IOException ex) {
  new AsciiOutputStream(true, encodeEolStrict);
try {
dh.writeTo(aos);
} catch (IOException ex) { }	// ignore it
if (aos.getAscii() == ALL_ASCII) // all ascii

代码示例来源:origin: stackoverflow.com

public static byte[] toBytes(DataHandler handler) throws IOException {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  handler.writeTo(output);
  return output.toByteArray();
}

代码示例来源:origin: apache/cxf

@Override
  protected byte[] getBytes(Object object) {
    DataHandler handler = (DataHandler) object;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      handler.writeTo(baos);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return baos.toByteArray();
  }
}

代码示例来源:origin: org.apache.cxf/cxf-rt-databinding-aegis

@Override
  protected byte[] getBytes(Object object) {
    DataHandler handler = (DataHandler) object;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      handler.writeTo(baos);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return baos.toByteArray();
  }
}

代码示例来源:origin: org.apache.axis2/axis2-transport-base

public void writeTo(MessageContext messageContext, OMOutputFormat format,
    OutputStream outputStream, boolean preserve) throws AxisFault {
  DataHandler dh = getDataHandler(messageContext);
  if (dh != null) {
    try {
      dh.writeTo(outputStream);
    } catch (IOException e) {
      throw new AxisFault("Error serializing binary content of element : " +
              BaseConstants.DEFAULT_BINARY_WRAPPER, e);
    }
  }        
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

public void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID, List/*<Header>*/ extraHeaders)
    throws IOException {
  OutputStream partOutputStream = writePart(dataHandler.getContentType(), contentTransferEncoding, contentID, extraHeaders);
  dataHandler.writeTo(partOutputStream);
  partOutputStream.close();
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core

public EncodedData getBytesFromDataHandler(DataHandler handler) {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  try {
    handler.writeTo(output);
  } catch (IOException ex) {
    throw ConversionException.couldNotBeConverted(handler, byte[].class, ex);
  }
  return new EncodedData(output.toByteArray(), handler.getContentType());
}

代码示例来源:origin: org.apache.axis2.transport/axis2-transport-testkit

@Override
  protected void checkMessageData(XMLMessage expected, XMLMessage actual) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Attachments attachments = actual.getAttachments();
    DataHandler dataHandler = attachments.getDataHandler(contentID);
    assertNotNull(dataHandler);
    dataHandler.writeTo(baos);
    assertTrue(Arrays.equals(attachmentContent, baos.toByteArray()));
  }
}

代码示例来源:origin: apache/cxf

@Override
  public void writeTo(OutputStream os) {
    JwsOutputStream jwsOutStream = new JwsOutputStream(os, sig, false);
    try {
      handler.writeTo(jwsOutStream);
      jwsOutStream.flush();
    } catch (Exception ex) {
      throw new JwsException(JwsException.Error.INVALID_SIGNATURE);
    }
  }
}

代码示例来源:origin: com.sun.xml.ws/jaxws-rt

public void write(OutputStream os) throws IOException {
    //build attachment frame
    writeln("--"+boundary, os);
    writeMimeHeaders(dh.getContentType(), contentId, os);
    dh.writeTo(os);
    writeln(os);
  }
}

代码示例来源:origin: com.sun.xml.ws/rt

public void write(OutputStream os) throws IOException {
    //build attachment frame
    writeln("--"+boundary, os);
    writeMimeHeaders(dh.getContentType(), contentId, os);
    dh.writeTo(os);
    writeln(os);
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize)
    throws IOException, XMLStreamException {
  finishStartElementIfNecessary();
  Base64EncodingWriterOutputStream out = new Base64EncodingWriterOutputStream(new ContentHandlerWriter(contentHandler), 4096, true);
  dataHandler.writeTo(out);
  out.complete();
}

相关文章