Y
yogesh
I am compressing/decompressing objects and sending them over http as
per the article mentioned in the URL below:-
http://java.sun.com/developer/technicalArticles/Programming/compression/
However I have a query regarding some code in which the following
sequence is depicted.
import java.io.*;
import java.util.zip.*;
public class SaveEmployee {
public static void main(String argv[]) throws
Exception {
// create some objects
Employee sarah = new Employee("S. Jordan", 28,
56000);
Employee sam = new Employee("S. McDonald", 29,
58000);
// serialize the objects sarah and sam
FileOutputStream fos = new
FileOutputStream("db");
GZIPOutputStream gz = new GZIPOutputStream(fos);
ObjectOutputStream oos = new
ObjectOutputStream(gz);
oos.writeObject(sarah);
oos.writeObject(sam);
oos.flush();
oos.close();
fos.close();
}
}
I wanted to know what is the logical explanation of the sequence of
the statements marked below
GZIPOutputStream gz = new GZIPOutputStream(fos);
ObjectOutputStream oos = new
ObjectOutputStream(gz);
oos.writeObject(sarah);
It seems to me that at the time the GZIPOutputStream is created, it is
empty and the then the empty stream is passed on to ObjectOutputStream
and then objects are written into the stream.
It seems to me that the logical sequence should be
ObjectOutputStream oos = new
ObjectOutputStream(fos);
oos.writeObject(sarah);
oos.writeObject(sam);
GZIPOutputStream gz = new GZIPOutputStream(oos);
gz.flush ();
gz.close();
oos.close();
i.e first the ObjectOutputStream is created,then objects are written
onto the stream and afterwards the stream is zipped using
GZIPOutputStream.
In my code if I try to reverse the order(the second case) I get the
error
java.io.EOFException
at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:200)
at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:190)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:130)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
Why doesnt this work ?.
Any help would be greatly appreciated
per the article mentioned in the URL below:-
http://java.sun.com/developer/technicalArticles/Programming/compression/
However I have a query regarding some code in which the following
sequence is depicted.
import java.io.*;
import java.util.zip.*;
public class SaveEmployee {
public static void main(String argv[]) throws
Exception {
// create some objects
Employee sarah = new Employee("S. Jordan", 28,
56000);
Employee sam = new Employee("S. McDonald", 29,
58000);
// serialize the objects sarah and sam
FileOutputStream fos = new
FileOutputStream("db");
GZIPOutputStream gz = new GZIPOutputStream(fos);
ObjectOutputStream oos = new
ObjectOutputStream(gz);
oos.writeObject(sarah);
oos.writeObject(sam);
oos.flush();
oos.close();
fos.close();
}
}
I wanted to know what is the logical explanation of the sequence of
the statements marked below
GZIPOutputStream gz = new GZIPOutputStream(fos);
ObjectOutputStream oos = new
ObjectOutputStream(gz);
oos.writeObject(sarah);
It seems to me that at the time the GZIPOutputStream is created, it is
empty and the then the empty stream is passed on to ObjectOutputStream
and then objects are written into the stream.
It seems to me that the logical sequence should be
ObjectOutputStream oos = new
ObjectOutputStream(fos);
oos.writeObject(sarah);
oos.writeObject(sam);
GZIPOutputStream gz = new GZIPOutputStream(oos);
gz.flush ();
gz.close();
oos.close();
i.e first the ObjectOutputStream is created,then objects are written
onto the stream and afterwards the stream is zipped using
GZIPOutputStream.
In my code if I try to reverse the order(the second case) I get the
error
java.io.EOFException
at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:200)
at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:190)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:130)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
Why doesnt this work ?.
Any help would be greatly appreciated