File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Copying zip files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Copying zip files" Watch "Copying zip files" New topic
Author

Copying zip files

Gabrielle Littler
Greenhorn

Joined: Feb 10, 2011
Posts: 7
Hi all,

I have a zip file containing compressed entries that I'm copying from a server to a client. My workflow is as follows:

1. Client connects to server. It doesn't have the zip, so copies from the server.
2. Some entries in the Zip on the server change slightly.
3. Client connects again and updates it's local copy by copying only the changed entries.

I have this all working fine using the standard java zip packages.

The problem I have is that when I read the zip entries on the server it decompresses them, then copies them, then recompresses them when I write them back to my copy on the client side. This isn't ideal because I want to minimise the data sent down the wire, and I also want to get rid of any time spent doing needless compression / decompression.

Does anyone know how I can get my hands on the raw, compressed bytes in the zip file? Or am I just going to have to roll my sleeves up and get stuck into the zip file spec myself?

Thanks in advance.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12676
    
    5
Due to the way Zip files build on a dictionary I don't think you can fiddle with the internals.

Link to wikipedia entry on zip structure.

Bill

Java Resources at www.wbrogden.com
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18124
    
    8

Gabrielle Littler wrote:Does anyone know how I can get my hands on the raw, compressed bytes in the zip file? Or am I just going to have to roll my sleeves up and get stuck into the zip file spec myself?


None of the above. If you want to compress the data you send over the wire and decompress it at the other end, it's perfectly possible to do that. All you have to do is to wrap the OutputStream on which you send data in a GZIPOutputStream. And at the other end, wrap the InputStream from which you receive data in a GZIPInputStream.

You'll find those classes in the java.util.zip package.
Gabrielle Littler
Greenhorn

Joined: Feb 10, 2011
Posts: 7
Thanks for the responses folks, much appreciated. Unfortunately neither of them quite address what I want to do.

Paul Clapham wrote:None of the above. If you want to compress the data you send over the wire and decompress it at the other end, it's perfectly possible to do that. All you have to do is to wrap the OutputStream on which you send data in a GZIPOutputStream. And at the other end, wrap the InputStream from which you receive data in a GZIPInputStream.


My bytes are already compressed in the server side zip. If I do that I'll be:

1. Reading the bytes from the zip
2. Decompressing the bytes
3. Compressing the bytes
4. Sending the bytes down the wire
5. Decompressing the bytes
6. Compressing the bytes again as I write them to the zip

That has lots of extra compression and decompression steps. I don't really mind that on the client, but I want my server to be as efficient as possible. What I really want is:

1. Read the bytes from the zip file
2. Send the (still compressed) bytes down the wire
3. Write the (still compressed) bytes to my zip file at the other end

William Brogden wrote:Due to the way Zip files build on a dictionary I don't think you can fiddle with the internals.


William, I can fiddle with the internals as much as I like . I just need to make sure I end up with a well-formed zip file that conforms to the file spec at the end of the process. I was hoping I wouldn't have to though, I could think of lots of ways I'd rather spend my time .

Looks like I might have to though. I was hoping to look in the source for the java Zip library and find how it looks up the location of the bytes for an entry in the dictionary, but unfortunately it's all done natively so it looks like I'll have to start from scratch. Unless anyone has any better ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Copying zip files
 
Similar Threads
URLyBird: RMI Server
Problem Creating ZIP File
generate large excel using zip stream
Combination Sockets and Threads
merge content of two zip filesinside two different folders