use of com.zimbra.common.util.tar.TarEntry 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);
}
}
Aggregations