May 21 2009

Unbelievably Simple Java Zip Example… And What About Reuse?

Category: Java,Software DevelopmentPhil @ 5:15 pm

I was working on a typical web portal application today and needed to support a multi-file download. Luckily, I had some code which I had used several times before. I started to tweak it for my specific requirements, realizing it was such a bad fit, I quickly tossed it out. My previous implementation worked with physical files and was tightly coupled to a legacy framework. This time, the files were already in memory. I was hoping to find some code that allowed me to build the zip file in memory, rather than dealing with the file system and temporary files. Since the portal user could only download a limited number of files at one time and the files were very small, I didn’t have to worry about memory constraints.

Bottom line, I found the perfect piece of code on Trip over IT. Within 15 minutes, my application was downloading a sweet little zip file! The code was so simple and concise, I had to share it. I will definitely put the code in my tool box of handy snippets. 

Here is a provocative thought: What is the point of a reusable library? Do we focus on reuse because we continually over-design and over-build our software, thinking that we are saving time by building these reusable libraries? Are there alternatives? What about simple, small, and disposable code? Don’t be so attached to your masterpiece. I promise, it will not look so elegant tomorrow! All you really need is Google to find some code to start with. I found this little snippet of code, changed it to fit my problem, and I was done within a few minutes, no support and minimal overhead. Maybe the real reuse is my memory and ability to relocate this snippet in the future… Or am I just crazy?

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png