CORE API / CATATAN</>↗Core API09 Jun 2008
In this example we demonstrate how to use the java.text.Collator class to sort strings in language-specific order. Using the java.text.Collator class makes the string not just sorted by the ASCII code of their characters, but it will follow the language natural order of the characters. package org.kodejava.text; import java.util.List; import java.util.ArrayList; import java.util.Locale; import java.text.Collator; […]
CORE API / CATATAN</>↗Core API06 Jun 2008
package org.kodejava.util; import java.util.*; public class ResourceBundleToProperties { public static void main(String[] args) { // Load resource bundle Messages_en_GB.properties from the classpath. ResourceBundle resource = ResourceBundle.getBundle("Messages", Locale.UK); // Call the convertResourceBundleToProperties method to convert the resource // bundle into a Properties object. Properties properties = convertResourceBundleToProperties(resource); // Print the entire con...
CORE API / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗Zip and GZIP30 Mei 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 / CATATAN</>↗Zip and GZIP27 Mei 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...