CORE API / NOTES</>↗Core API06 Jun 2008
The following code snippet will convert a resource bundle into a map object, a key-value mapping. It will read from a file called Messages_en_GB.properties which corresponding to the Locale.UK. For example the file contain the following string. This file should be placed under the resources directory. welcome.message = Hello World! package org.kodejava.util; import java.util.*; public […]
ZIP AND GZIP / NOTES</>↗Zip and GZIP02 Jun 2008
In the previous example How do I compress Java objects? we have manage to compress Java objects and stored them in file. In this example we will read the file and reconstruct the compressed objects. For the User class you can see in the previous example mentioned above. package org.kodejava.util.zip; import org.kodejava.util.support.User; import java.io.File; import […]
ZIP AND GZIP / NOTES</>↗Zip and GZIP30 May 2008
This example demonstrates how to compress a Java object. We compress the Java object using GZIPOutputStream, pass it to ObjectOutputStream to write the object into an external file. The object we are going to compress will be represented by the User object. We need to make the User object serializable, so it must implement the […]
ZIP AND GZIP / NOTES</>↗Zip and GZIP27 May 2008
package org.kodejava.util.zip; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; import java.util.zip.CheckedInputStream; import java.util.zip.Adler32; public class UnzipWithChecksum { public static void main(String[] args) throws Exception { String zipName = "data-1.zip"; try (FileInputStream fis = new FileInputStream(zipName); // Creating input stream that also maintains the checksum of // the data which later can be used to validate data...
ZIP AND GZIP / NOTES</>↗Zip and GZIP25 May 2008
This example demonstrate how to use CheckedOutputStream for creating a checksum of a zip file. Checksum can be used to detect whether a data was corrupted during a transmission process to a remote machine. package org.kodejava.util.zip; import java.io.*; import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import java.util.zip.CheckedOutputStream; import java.util.zip.Adler32; public class ZipWithChecksum { public static void […]
ZIP AND GZIP / NOTES</>↗Zip and GZIP20 May 2008
In this example we use the java.util.zip.ZipFile class to decompress and extract a zip file. package org.kodejava.util.zip; import java.util.zip.ZipFile; import java.util.zip.ZipEntry; import java.util.Enumeration; import java.io.*; public class ZipFileUnzipDemo { public static void main(String[] args) throws Exception { String zipName = "data.zip"; ZipFile zip = new ZipFile(zipName); Enumeration<? extends ZipEntry> enumeration = zip.entries(); while (enumeration.hasMoreEleme...