APACHE COMMONS / CATATAN</>↗Apache Commons06 Feb 2019
The following code snippet demonstrates how to use RandomStringGenerator class from the Apache Commons Text library to generate random strings. To create an instance of the generator we can use the RandomStringGenerator.Builder() class build() method. The builder class also helps us to configure the properties of the generator. Before calling the build() method we can […]
APACHE COMMONS / CATATAN</>↗Apache Commons02 Jan 2017
To sort file names by their extension, we can use the ExtensionFileComparator class from the Apache Commons IO library. This class provides a couple instances of comparator such as: Comparator Description EXTENSION_COMPARATOR Case sensitive extension comparator EXTENSION_REVERSE Reverse case sensitive extension comparator EXTENSION_INSENSITIVE_COMPARATOR Case insensitive extension comparator EXTENSION_INSENSITIVE_REVERSE Reverse case insensitive extension comparator EXTENSION...
APACHE COMMONS / CATATAN</>↗Apache Commons02 Jan 2017
In this example, you will learn how to sort files and directories based on their size. Using the Apache Commons IO, we can utilize the SizeFileComparator class. This class provides some instances to sort file size such as: Comparator Description SIZE_COMPARATOR Size comparator instance – directories are treated as zero size SIZE_REVERSE Reverse size comparator […]
APACHE COMMONS / CATATAN</>↗Apache Commons01 Jan 2017
The following example show how to use the Apache Commons IO library to read a text file line by line to a List of String. In the code snippet below we will read the contents of a file called sample.txt using FileUtils class. We use FileUtils.readLines() method to read the contents line by line and […]
APACHE COMMONS / CATATAN</>↗Apache Commons19 Jul 2013
In this example you’ll learn how to generate an SHA-1 digest using the Apache Commons Codec DigestUtils class. In the last two examples you’ve already seen how to generate the MD5 digest using the same library. Compared to the MD5 version the SHA-1 digest is known to be stronger to brute force attacks, but it […]
APACHE COMMONS / CATATAN</>↗Apache Commons18 Jul 2013
In the How do I calculate the MD5 digest of a string? example you can see how to calculate the MD5 digest from a text or a string. We are using the Apache Commons Codec library and use the DigestUtils.md5Hex() method to generate the MD5. I’ve mentioned in that post that we can also generate […]