Try compiling and running the below - its not the best bit of code out, and could do with some refining, but it basically does what I think you are after - ie - it opens up zipoutputstreams etc, and lets you write out compressed lines on the fly, and appears to unzip those lines quite happily (though with a stack of whitespace, but I'm sure you could get around that with some String.trim() somewhere)
once the streams are all closed up. See what you think anyway !
Ben
import java.io.*;
import java.util.zip.*;
public class ZipFileTest {
FileOutputStream fos;
GZIPOutputStream gzos;
Checksum check;
static CheckedOutputStream cos;
public void openStreams() {
try {
fos = new FileOutputStream(new File("file_compress_out.txt"

);
gzos = new GZIPOutputStream(fos);
check = new Adler32();
cos = new CheckedOutputStream(gzos, check);
}
catch (IOException e) {
System.out.println("IO Error .... " +e.toString());
}
}
public void addZIPLine(String s) {
StringBufferInputStream sbis = new StringBufferInputStream(s);
try {
byte[] buffer = new byte[4096];
int bytes_read = 0;
while ((bytes_read = sbis.read(buffer)) != -1) {
cos.write(buffer);
}
}
catch (IOException e) {
System.out.println("IO Error .... " +e.toString());
}
}
public void closeStreams() {
try {
cos.close();
gzos.close();
fos.close();
}
catch (IOException e) {
System.out.println("IO Error .... " +e.toString());
}
}
public void GZIP_UnCompressFile() {
try {
File out_file = new File("file_uncompress_out.txt"

;
File in_file = new File("file_compress_out.txt"

;
FileInputStream fis = new FileInputStream(in_file);
GZIPInputStream gzis = new GZIPInputStream(fis);
Checksum check_in = new Adler32();
CheckedInputStream cis = new CheckedInputStream(gzis, check_in);
FileOutputStream fos = new FileOutputStream(out_file);
byte[] buffer_in = new byte[4096];
int bytes_read_in = 0;
while ((bytes_read_in = cis.read(buffer_in)) != -1) {
fos.write(buffer_in);
}
fos.close();
long sum = check_in.getValue();
}
catch (IOException e) {
System.out.println("IO Error .... " +e.toString());
}
}
public static void main(String args[]) {
ZipFileTest app = new ZipFileTest();
app.openStreams();
app.addZIPLine("hello"

;
app.addZIPLine("there"

;
app.closeStreams();
app.GZIP_UnCompressFile();
}
}