use of com.zimbra.common.util.InputStreamWithSize in project zm-mailbox by Zimbra.
the class ImapPartSpecifierTest method checkPartial.
private void checkPartial(MimeMessage mm, String part, String modifier, int start, int count, String startsWith, String endsWith) throws IOException, BinaryDecodingException, ServiceException {
ImapPartSpecifier pspec = new ImapPartSpecifier("BODY", part, modifier, start, count);
InputStreamWithSize content = pspec.getContentOctetRange(mm);
if (startsWith == null) {
Assert.assertNull(pspec.getSectionSpec() + " is null", content);
} else {
Assert.assertNotNull(pspec.getSectionSpec() + " is not null", content.stream);
String data = new String(ByteUtil.getContent(content.stream, content.size.intValue())).trim();
if (startsWith.length() > 0) {
Assert.assertTrue(pspec.getSectionSpec() + " start matches", data.startsWith(startsWith));
} else {
Assert.assertTrue(pspec.getSectionSpec() + " start empty", data.length() == 0);
}
if (endsWith.length() > 0) {
Assert.assertTrue(pspec.getSectionSpec() + " end matches", data.endsWith(endsWith));
} else {
Assert.assertTrue(pspec.getSectionSpec() + " end empty", data.length() == 0);
}
}
}
Aggregations