Java and JVM

Java and JVM

Filtered extraction from zip file using ZipInputStream and Java 8

By dave on May 16, 2015

In the example below we build on the Reading a zip file from java using ZipInputStream page to provide basic filtering. This filtering is provided by the filteredExpandZipFile method taking a Predicate. Every ZipEntry is passed to the predicate, but only ones that match (predicate returns true) are included. Note that the size of an entry cannot be accurately determined in all cases, so it is not safe to perform validation on the this field.

Writing a zip file in java using ZipOutputStream.

By dave on April 27, 2015

Following on from one of our popular articles on Reading a zip file from java using ZipInputStream we’ve put together a new article on how to create a zip archive using Java. The below example uses ZipOutputStream to create a zip file from all the items in a directory. Zip files are written slightly differently to a normal stream in that each entry is put into the stream one at a time.

Reading a GZIP file using Java

By dave on July 1, 2012

Another common compression file format on Linux is the GZIP format. Java again has out of the box support for this file format. Gzip files differ from zip files in that they only contain one file, the compressed form of the original file with a .gz extension. Java’s GZipInputStream takes such a file type and decompresses it. We can treat GZipInputStream directly like a FileInputStream. Here is an example that expands such a file to disk

Reading a zip file from java using ZipInputStream

By dave on July 1, 2012

Java provides support for reading zip files in the form of ZipInputStream. This class provides an API where you can iterate over all the items in a given zip file, reading the data from the archive for each file. In order to do this, first you must create the ZipInputStream instance giving the file that you wish to expand. Then you iterate using the getNextEntry method on the stream, which returns the header data for each entry in turn.


By system on April 25, 2015

Optimisation This area of the website discusses JVM optimisation and analysis techniques. This subject tends to trigger quite strong reactions in people, and it’s not unusual for there to be many differing opinions on this subject. My aim is to provide articles that are based on evidence and follow best practice.

We use cookies to analyse traffic and to personalise content and adverts. Our social buttons may also use cookies.