Example usage for org.apache.poi.hsmf.datatypes ByteChunk getValue

List of usage examples for org.apache.poi.hsmf.datatypes ByteChunk getValue

Introduction

In this page you can find the example usage for org.apache.poi.hsmf.datatypes ByteChunk getValue.

Prototype

public byte[] getValue() 

Source Link

Usage

From source file:org.alfresco.repo.content.transform.MSGParser.java

License:Apache License

/**
 * Prepare extract multipart by filling attachment list.
 *
 * @param xhtml/*from   w  ww .j a  va 2  s  .  c o m*/
 *            the xhtml
 * @param msg
 *            the message
 * @param attachmentList
 *            is list with attachments to fill
 * @throws MessagingException
 *             the messaging exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws SAXException
 *             the sAX exception
 * @throws TikaException
 *             the tika exception
 */
private void prepareExtractMultipart(XHTMLContentHandler xhtml, MAPIMessage msg, List<String> attachmentList)
        throws MessagingException, IOException, SAXException, TikaException {

    // Process the attachments
    for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
        String filename = null;
        if (attachment.attachLongFileName != null) {
            filename = attachment.attachLongFileName.getValue();
        } else if (attachment.attachFileName != null) {
            filename = attachment.attachFileName.getValue();
        }

        if (filename != null && filename.length() > 0) {
            Chunk[] chunks = attachment.getChunks();
            String id = null;
            byte[] data = null;
            // String mimetype = null;
            for (Chunk chunk : chunks) {
                if (MAPIProperty.ATTACH_CONTENT_ID.id == chunk.getChunkId()) {
                    id = chunk.toString();
                    // } else if (MAPIProperty.ATTACH_MIME_TAG.id == chunk
                    // .getChunkId()) {
                    // mimetype = chunk.toString();
                } else if (MAPIProperty.ATTACH_DATA.id == chunk.getChunkId() && (chunk instanceof ByteChunk)) {
                    ByteChunk chunkByte = (ByteChunk) chunk;
                    data = chunkByte.getValue();

                }

            }
            if (id != null && data != null) {
                File file = new File(workingDirectory, System.currentTimeMillis() + "");
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                IOUtils.copy(new ByteArrayInputStream(data), fileOutputStream);
                IOUtils.closeQuietly(fileOutputStream);
                String src = file.getName();
                String replace = id.replace("<", "").replace(">", "");
                // String encodedData = new
                // String(Base64.encodeBase64(data));
                // String src = "data:" + mimetype + ";base64," +
                // encodedData;

                referencesCache.put(replace, src);
            } else {
                attachmentList.add(filename);
            }
        }

    }
}