Sidebar

How do I zip up a message before sending it?

0 votes
288 views
asked Dec 28, 2016 by ben-s-7515 (12,640 points)
I need to zip a message before sending it to the other system.  How do I go about zipping up the message?

1 Answer

+1 vote

Zipping file/message content can be done using the standard java libraries.  Here is an example function:

var outputStream = new java.io.ByteArrayOutputStream();
var zipFileStream = new java.util.zip.ZipOutputStream(outputStream);
try {
  // we will get the message bytes to add to the zip file
   var fileBytes = message.getBytes();
   var fileName = 'myZipEntry';
   
   var zipEntry = new java.util.zip.ZipEntry(fileName);
   zipEntry.setCreationTime(java.nio.file.attribute.FileTime.fromMillis(new Date().getTime()));
   zipFileStream.putNextEntry(zipEntry);

   zipFileStream.write(fileBytes, 0, fileBytes.length);
} finally {
   zipFileStream.close();
}
// set the message to a binary message representing the zip file.
message = qie.createBinaryMessage(outputStream.toByteArray(), 'ISO-8859-1');

answered Dec 28, 2016 by ben-s-7515 (12,640 points)
...