/**
   * Zips byte array.
   *
   * @param input Input bytes.
   * @param initBufSize Initial buffer size.
   * @return Zipped byte array.
   * @throws IOException If failed.
   */
  public static byte[] zipBytes(byte[] input, int initBufSize) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(initBufSize);

    try (ZipOutputStream zos = new ZipOutputStream(bos)) {
      ZipEntry entry = new ZipEntry("");

      try {
        entry.setSize(input.length);

        zos.putNextEntry(entry);

        zos.write(input);
      } finally {
        zos.closeEntry();
      }
    }

    return bos.toByteArray();
  }
 private ByteBuffer buffer(Message m[]) throws Exception {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   for (int i = 0; i < m.length; i++) m[i].write(out);
   out.flush();
   return ByteBuffer.wrap(out.toByteArray());
 }
 private ByteBuffer buffer(List ms) throws Exception {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   for (Iterator i = ms.iterator(); i.hasNext(); ) ((Message) i.next()).write(out);
   out.flush();
   return ByteBuffer.wrap(out.toByteArray());
 }
 private ByteBuffer buffer(Message m) throws Exception {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   m.write(out);
   out.flush();
   return ByteBuffer.wrap(out.toByteArray());
 }