Example usage for javax.mail.util SharedByteArrayInputStream SharedByteArrayInputStream

List of usage examples for javax.mail.util SharedByteArrayInputStream SharedByteArrayInputStream

Introduction

In this page you can find the example usage for javax.mail.util SharedByteArrayInputStream SharedByteArrayInputStream.

Prototype

public SharedByteArrayInputStream(byte[] buf) 

Source Link

Document

Create a SharedByteArrayInputStream representing the entire byte array.

Usage

From source file:org.apache.james.util.ClassLoaderUtils.java

public static SharedByteArrayInputStream getSystemResourceAsSharedStream(String filename) {
    return new SharedByteArrayInputStream(getSystemResourceAsByteArray(filename));
}

From source file:org.xwiki.contrib.mail.internal.DefaultMailReader.java

/**
 * {@inheritDoc}/*from w  w  w. j  a v a 2s  .c  o m*/
 * 
 * @see org.xwiki.contrib.mail.IMailReader#cloneEmail(javax.mail.Message, java.lang.String, java.lang.String)
 */
public MimeMessage cloneEmail(final Message mail) {
    MimeMessage cmail = null;
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        mail.writeTo(bos);
        bos.close();
        SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray());

        cmail = new MimeMessage(this.session, bis);
        bis.close();
    } catch (Exception e) {
        logger.warn("Could not clone email", e);
        return null;
    }

    return cmail;
}

From source file:se.inera.axel.shs.camel.ShsMessageTypeConverter.java

@Converter
public static ShsMessage byteArrayToShsMessage(byte[] byteArray) throws Exception {
    log.trace("Converting byte array to ShsMessage");
    return inputStreamToShsMessage(new SharedByteArrayInputStream(byteArray));
}

From source file:se.inera.axel.shs.camel.ShsMessageTypeConverter.java

@Converter
public static ShsMessage stringToShsMessage(String string) throws Exception {
    log.trace("Converting String to ShsMessage");
    return inputStreamToShsMessage(new SharedByteArrayInputStream(string.getBytes()));
}

From source file:se.inera.axel.shs.processor.SharedDeferredStream.java

public static InputStream toSharedInputStream(DeferredFileOutputStream outputStream) throws IOException {
    if (outputStream.isInMemory()) {
        if (log.isTraceEnabled())
            log.trace("written to memory");

        return new SharedByteArrayInputStream(outputStream.getData());
    } else {//from w w  w  . j a v a 2s  .  c o m
        if (log.isTraceEnabled())
            log.trace("written to file: " + outputStream.getFile());

        File outputFile = outputStream.getFile();
        if (outputFile != null) {
            outputFile.deleteOnExit();
        }

        return new SharedTemporaryFileInputStream(outputStream.getFile());
    }
}