Code example for GZIPOutputStream

Methods: writeflushfinish

  /** Compress the document. */ 
  public static byte[] compress(final byte[] raw) throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final GZIPOutputStream gz = new GZIPOutputStream(out);
    return out.toByteArray();
  /** Convert a document to a String, assuming later encoding to UTF-8. */ 
  public static String toString(final Document hostDoc) throws IOException {
    try { 
      final StringWriter out = new StringWriter();
      final DOMSource domSource = new DOMSource(hostDoc);
      final StreamResult streamResult = new StreamResult(out);
      final TransformerFactory tf = TransformerFactory.newInstance();
      final Transformer serializer = tf.newTransformer();
Connect your IDE to all the code out there  Get Codota for Java