Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ZipOutputStream and binary data

Reply
Thread Tools

ZipOutputStream and binary data

 
 
JScoobyCed
Guest
Posts: n/a
 
      06-23-2004
I used the zip package to create a Zip file. The list of files I put in the
archive was a set of binary data. After I use Winzip on the client side to
extract and get back the original files, they are differents. Those binary
data contains an internal CRC and when the system checks it, it fails. The
binaries are really big and I didn't analyse which byte could be wrong.
Both server and client use the same OS, and JRE 1.4.1_04

JScoobyCed
-------------


 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      06-23-2004
JScoobyCed wrote:
> I used the zip package to create a Zip file. The list of files I put in the
> archive was a set of binary data. After I use Winzip on the client side to
> extract and get back the original files, they are differents. Those binary
> data contains an internal CRC and when the system checks it, it fails. The
> binaries are really big and I didn't analyse which byte could be wrong.
> Both server and client use the same OS, and JRE 1.4.1_04


Well, it's not the case that ZipOutputStream is universally broken, if
that's what you were expecting to hear. I've used it on several
occasions and it has worked fine for me, without fail.

Not to belabour the obvious, but to get any further we'd need to
actually see your code that's not working.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      06-23-2004

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)4.net...
> JScoobyCed wrote:
> > I used the zip package to create a Zip file. The list of files I put in

the
> > archive was a set of binary data. After I use Winzip on the client side

to
> > extract and get back the original files, they are differents. Those

binary
> > data contains an internal CRC and when the system checks it, it fails.

The
> > binaries are really big and I didn't analyse which byte could be wrong.
> > Both server and client use the same OS, and JRE 1.4.1_04

>
> Well, it's not the case that ZipOutputStream is universally broken, if
> that's what you were expecting to hear. I've used it on several
> occasions and it has worked fine for me, without fail.
>
> Not to belabour the obvious, but to get any further we'd need to
> actually see your code that's not working.
>


I'd have to agree with chris. I've never seen a corruption from the java zip
functions.

try and find the smallest file that goes wrong, and then do a byte-by-byte
analysis - there's no other way to find out what the differences are, and
that's your best chance of working out where they came from.

analyzing it at this level will also force you to look real close at the
code and data, and it might even point you at some mistake in your code.

> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation



 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-23-2004
Andy Fish wrote:
> analyzing it at this level will also force you to look real close at the
> code and data, and it might even point you at some mistake in your code.


My crystal ball tells me that something is wrong with the way the data
is read in the Java program before it is written to the zip file. Maybe
instead of using an InputStream the OP is using a Reader or some other
inappropriate class.

/Thomas
 
Reply With Quote
 
Andy Fish
Guest
Posts: n/a
 
      06-23-2004
"Thomas Weidenfeller" <(E-Mail Removed)> wrote in message
news:cbbns1$i4j$(E-Mail Removed)...
> Andy Fish wrote:
> > analyzing it at this level will also force you to look real close at the
> > code and data, and it might even point you at some mistake in your code.

>
> My crystal ball tells me that something is wrong with the way the data
> is read in the Java program before it is written to the zip file. Maybe
> instead of using an InputStream the OP is using a Reader or some other
> inappropriate class.
>


the strange thing is IIRC you normally just pass the names of the files into
the zip function - you don't have to read the file itself

> /Thomas



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-23-2004
On Wed, 23 Jun 2004 13:02:42 +0200, Thomas Weidenfeller
<(E-Mail Removed)> wrote or quoted :

>
>My crystal ball tells me that something is wrong with the way the data
>is read in the Java program before it is written to the zip file. Maybe
>instead of using an InputStream the OP is using a Reader or some other
>inappropriate class.


See http://mindprod.com/fileio.html
for how to use GZIP (a sort of one-member zip file).

It uses the same guts as ZipFile.

When you get your code working with that, flip back to ZipFile.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      06-23-2004

"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Wed, 23 Jun 2004 13:02:42 +0200, Thomas Weidenfeller
> <(E-Mail Removed)> wrote or quoted :
>
> >
> >My crystal ball tells me that something is wrong with the way the data
> >is read in the Java program before it is written to the zip file. Maybe
> >instead of using an InputStream the OP is using a Reader or some other
> >inappropriate class.

>
> See http://mindprod.com/fileio.html
> for how to use GZIP (a sort of one-member zip file).
>
> It uses the same guts as ZipFile.
>
> When you get your code working with that, flip back to ZipFile.
>


I use GZIP and it is really great. Here is how I set up to read a 'csv' file
====
if (filename.endsWith("csv.gz"))
in = new BufferedReader(new InputStreamReader(new
GZIPInputStream(new FileInputStream(filename))));
else if (filename.endsWith("csv"))
in = new BufferedReader(new FileReader(filename));


 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      06-23-2004
Thomas Weidenfeller wrote:
> My crystal ball tells me that something is wrong with the way the data
> is read in the Java program before it is written to the zip file. Maybe
> instead of using an InputStream the OP is using a Reader or some other
> inappropriate class.


This is fairly similar to what my own crystal ball is saying; that
there's probably an error in dealing with I/O streams somewhere.
Perhaps it's in the input, or perhaps it's in the output. Either way,
we won't know until we see the code.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
JScoobyCed
Guest
Posts: n/a
 
      06-24-2004
Thanks all for your reply (I was off for a day, didn't check the news)
I think my code is really basic I/O with no Reader or Writer:


 
Reply With Quote
 
JScoobyCed
Guest
Posts: n/a
 
      06-24-2004
Thanks all for your reply (I was off for a day and didn't check the new).
I think my code is basic and there is no Reader or Writer. Or is the
BufferedInputStream creating problem ?

---------------------------------------------
public class ZipUtility {
private Vector files = null;
private String path, name;
public ZipUtility(String p, String n) {
path = p;
name = n;
}

public void addFile(File f) {
if(files==null)
files = new Vector();
files.addElement(f);
}

public void doZip() throws Exception {
FileOutputStream fo = new FileOutputStream(new File(new File(path),
name));
ZipOutputStream zo = new ZipOutputStream(fo);
byte[] buf = new byte[512];
BufferedInputStream bi;
int c;
File f;
for(Enumeration en = files.elements();en.hasMoreElements() {
f = new File(en.nextElement().toString());
bi = new BufferedInputStream(new FileInputStream(f));
zo.putNextEntry(new ZipEntry(f.getName()));
while((c = bi.read(buf)) != -1) {
zo.write(buf);
}
zo.flush();
zo.closeEntry();
bi.close();
}
zo.close();
fo.close();
}
}
----------------------------------------------------------

JScoobyCed
-------------


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ZipOutputStream Erik Java 14 01-30-2010 12:35 PM
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
Issue with ZipOutputStream class in my .net application. VijayV Java 2 04-11-2008 05:57 AM
ZipOutputStream, ZipFile and Linux unzip do not agree on the file count in zip C B Java 4 11-10-2004 11:13 AM
ZipoutputStream Reading/ adding zip file comments Claudio Barradas Java 1 06-22-2004 11:55 PM



Advertisments