This may or may not be related: When I was attempting to create compressed ZIP files, I discovered that there is an error in the logic between the ZIP header and the ZIP io stream. I ended up opting to compress the data separately, and then storing the "compressed data" in an uncompressed ZIP file. George P.S. Be warned, there is a bug in the "strait array" (no bounds) method in either compress or decompress (I can look it up if you need). At 02:07 AM 2/11/00 -0800, Tom Rochelle wrote: >Hi Everyone: > >Any ideas as to why the following code doesn't work? It generates the following exception: >I've concluded that the writeObject with the GZIPOutputStream in the mix doesn't generate >the byte array that should be generated. Thus, an exception is thrown when the byte array is >decompressed. I'm hoping to generate an array of bytes containing the compressed object. >Using jdk1.2.2. > >Per my reading of O'Reilly's Java Examples in a Nutshell pp 266-7 and >Sun's http://forum.java.sun.com/forum?[EMAIL PROTECTED]^[email protected]/0 > >the code should work. > >the Exception: > >Exception is Caught EOFException while reading the stream header >java.io.StreamCorruptedException: Caught EOFException while reading the stream header > at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:727) > at java.io.ObjectInputStream.<init>(ObjectInputStream.java:165) > at examples.ejb.basic.rc.TestIt.main(TestIt.java, Compiled Code) > >the code: > >import java.util.*; >import java.util.zip.*; >import java.io.*; > > public class TestIt { > > public static void main(String[] args) > { > try > { > Vector names = new Vector(); > String fred = "fred"; > String skip = "skip"; > String lisa = "lisa"; > > names.addElement(fred); > names.addElement(skip); > names.addElement(lisa); > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > GZIPOutputStream gos = new GZIPOutputStream( baos ); > ObjectOutputStream oos = new ObjectOutputStream( gos ); > oos.writeObject( names ); > oos.flush(); > > //This is required > byte[] data = baos.toByteArray(); > //This is required > > oos.close(); > > ByteArrayInputStream bin = new ByteArrayInputStream( data ); > GZIPInputStream gin = new GZIPInputStream( bin ); > ObjectInputStream ois = new ObjectInputStream( gin ); > Vector v = (Vector)ois.readObject(); > ois.close(); > > Enumeration enum = v.elements(); > String stuff; > while ( enum.hasMoreElements() ) > { > stuff = (String)enum.nextElement(); > System.out.println("Name is " + stuff); > } > } > catch( Exception e ) > { > System.out.println( "Exception is " + e.getMessage() ); > e.printStackTrace(); > } > } >} > > >Thanks if you can take a quick look. > >Tom Rochelle > >====================================================================== >-Continued posting eligibility is subject to adherence to >the list charter posted at: http://www.seajug.org/html/mail.html- >Subscribe / Unsubscribe to: [EMAIL PROTECTED] >Subscribe / Unsubscribe instructions: http://www.seajug.org/html/mail.html >List Admin: [EMAIL PROTECTED] >Seattle Java Users Group (SeaJUG) info: http://www.seajug.org/ > --------------------- Smith's Net Services 9505 S. 241 St. Kent, WA 98031 USA Fon: 1.253.813-8698 Fax: 1.253.813-8532 http://www.SNS.to mailto:[EMAIL PROTECTED] "Inside every small problem is a big one trying to get government funding." -- Source Unknown --------------------- =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
