Skip to content

Instantly share code, notes, and snippets.

@twmht
Created December 25, 2014 15:24
Show Gist options
  • Save twmht/ffa6950356e505f6b2d0 to your computer and use it in GitHub Desktop.
Save twmht/ffa6950356e505f6b2d0 to your computer and use it in GitHub Desktop.
Gzip
package org.gradle;
import java.io.PrintWriter;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.zip.GZIPOutputStream;
import java.util.zip.GZIPInputStream;
import org.apache.commons.collections.list.GrowthList;
public class Person {
private final String name;
public Person(String name) {
this.name = name;
new GrowthList();
}
public String getName() {
return name;
}
public static void main(String[] args) {
try{
ByteArrayOutputStream bao = new ByteArrayOutputStream();
GZIPOutputStream gzo = new GZIPOutputStream(bao);
PrintWriter pw = new PrintWriter(gzo);
pw.println("Hello world!");
pw.close();
byte [] data = bao.toByteArray();
ByteArrayInputStream bai = new ByteArrayInputStream(data);
GZIPInputStream gzi = new GZIPInputStream(bai);
InputStreamReader reader = new InputStreamReader(gzi);
BufferedReader in = new BufferedReader(reader);
String str;
while((str = in.readLine()) != null){
System.out.println(str);
}
}catch(Exception IOException){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment