In a recent project, we had to do something I had personally never really had to look at; Compression. We needed to take a couple files and images, zip them up and make them available for FTP, and yes somedays it does feel like we are back in the 90's. Besides the FTP trip into the past its was good opportunity to spend a little bit of time on the subject.
So above the usual IO classes BufferedInputStream, FileOutputStream and File there are:
ZipInputStream - An input stream for reading files in the ZIP file format. Zip entries are not cached, unlike ZipFile.
ZipOutputStream - An output stream for writing files in the ZIP file format. This has a default internal buffer of 512, a BufferedOutputStream can be used to increase this.
ZipEntry - Represents an entry int a zip file.
ZipFile - Used to read entries from a zip file. The entries are cached.
CRC32 - Used to compute the CRC-32 of a data stream.
Below is an example showing how to compress and decompress files in a folder, with and without a checksum:
We didn't end up using object compression but I had a look at it anyways. I did a little generic compress / expand util, don't know if it will ever be useful. I left the input params as OutputStream and InputStream as this could theoretically be used with any stream implementation from socket communication to string manipulation.
The compression related classes being used here:
GZIPInputStream - An input stream filter for reading compressed data in the GZIP file format.
GZIPOutputStream - An output stream filter for writing compressed data in the GZIP file format. Default internal buffer of 512, use BufferedOutputStream if you require more.
I have recently been slacking on content on my blog, between long stressful hours at work and to the wonderful toy that is an iPhone, I have...
I make no claim to be a "computer scientist" or a software "engineer", those titles alone can spark some debate, I regar...
I saw an article (well more of a rant) the other day, by Rob Williams Brain Drain in enterprise Dev . I have to say, I do agree with some o...
This series of posts will be about me getting to grips with JBoss Drools . The reasoning behind it is: SAP bought out my company's curre...
Update: Check out my updated re-certification on the new 2019 exam... here Let me start by saying, for this certification I studied and...