Search in sources :

Example 1 with TarInputStream

use of com.zimbra.common.util.tar.TarInputStream in project zm-mailbox by Zimbra.

the class TestUserServlet method verifyTarball.

private void verifyTarball(ZMailbox mbox, String relativePath, boolean hasMeta, boolean hasBody) throws Exception {
    InputStream in = mbox.getRESTResource(relativePath);
    TarInputStream tarIn = new TarInputStream(new GZIPInputStream(in), "UTF-8");
    TarEntry entry = null;
    boolean foundMeta = false;
    boolean foundMessage = false;
    while ((entry = tarIn.getNextEntry()) != null) {
        if (entry.getName().endsWith(".meta")) {
            Assert.assertTrue("Fround " + entry.getName(), hasMeta);
            foundMeta = true;
        }
        if (entry.getName().endsWith(".eml")) {
            byte[] content = new byte[(int) entry.getSize()];
            Assert.assertEquals(content.length, tarIn.read(content));
            MimeMessage message = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content));
            byte[] body = ByteUtil.getContent(message.getInputStream(), 0);
            if (hasBody) {
                Assert.assertTrue(entry.getName() + " has no body", body.length > 0);
            } else {
                Assert.assertEquals(entry.getName() + " has a body", 0, body.length);
            }
            foundMessage = true;
        }
    }
    tarIn.close();
    Assert.assertTrue(foundMessage);
    if (hasMeta) {
        Assert.assertTrue(foundMeta);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) TarInputStream(com.zimbra.common.util.tar.TarInputStream) ZipInputStream(java.util.zip.ZipInputStream) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) InputStream(java.io.InputStream) TarInputStream(com.zimbra.common.util.tar.TarInputStream) TarEntry(com.zimbra.common.util.tar.TarEntry) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream)

Aggregations

TarEntry (com.zimbra.common.util.tar.TarEntry)1 TarInputStream (com.zimbra.common.util.tar.TarInputStream)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1 MimeMessage (javax.mail.internet.MimeMessage)1 SharedByteArrayInputStream (javax.mail.util.SharedByteArrayInputStream)1