This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Copying zip files

 
Gabrielle Littler
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Posts: 20713
29
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic