In this post under Apache Commons IO, I will show with example how to get URL of a resource present in application classpath. “IOUtils” class provides a static method “resourceToURL” which takes the resource name and the classloader as arguments and returns url of the resource. Below is the main class showing how to use…… Continue reading Getting URL of classpath resource
Using @Builder annotation example
In this post under Lombok, I will show with example how to use “@Builder” annotation to implement Builder Pattern in our application. For our example, we use the below Person pojo class. Person class package package26; public class Person { private String name; private String city; @Override public String toString() { StringBuilder stringBuilder = new…… Continue reading Using @Builder annotation example
autoGrowCollections example
In this post under Spring SpEL, I will show with example the purpose of “autoGrowCollections” configuration. When evaluating a SpEL expression, containing collections, if we try to access an entry which doesn’t exist in collection. We get an exception. Lets say we have the below pojo class Employee package spel.package22; public class Employee { private…… Continue reading autoGrowCollections example
MappingConstants.ANY_UNMAPPED example
In this post under MapStruct, I will explain with example the purpose of MappingConstants.ANY_UNMAPPED enum. This enum is used when mapping two enums with different constant names. It indicates MapStruct that any unmapped enum constant (i.e., source enum constant without any explicit mapping) must be mapped to a particular target enum constant. The specific target…… Continue reading MappingConstants.ANY_UNMAPPED example
File copy example
In this post under Apache Commons IO, I will explain with example how to copy a file. Apache provides “IOUtils” static class which has static method “copy”. We can use this “copy” method to copy files. Below is the complete main code for your reference. Main class package ioutils; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileReader;…… Continue reading File copy example
Checking whether contents of two files are equal or not
In this post under Apache Commons IO, I will show with example the easiest way to compare whether contents of two files are equal or not. Apache Commons “IOUtils” class provide a static method called “contentEquals” which compare contents of two file and return a boolen. Below is the complete main code Main class package…… Continue reading Checking whether contents of two files are equal or not
autoGrowNullReferences example
In this post under Spring SpEL, I will show with example the purpose of “autoGrowNullReferences” configuration. When evaluating a SpEL expression, containing chain of property references, if one of the property in the chain is null we get an exception. To prevent that we use the “autoGrowNullReferences” configuration. It’s data type is boolean. By default…… Continue reading autoGrowNullReferences example
Reading file and ignoring its contents
In this post under Apache Commons IO, I will show with example how to read a file and ignore the contents that we have read. In Apache Commons IO framework, we have static utility class “IOUtils”, which has a method “consume” which reads a file and ignore the contents that it has read. Below is…… Continue reading Reading file and ignoring its contents
Mapping two enums with different constant name
In this post under MapStruct I will show with example how to map two enums having different constant name. For our example lets say you have to map below enum Day package package12; public enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; } to below enum Week package package12; public enum Week {…… Continue reading Mapping two enums with different constant name
Making Java objects available during sqel expression evaluation
In this post under Spring SpEL, I will explain with example how to make java objects available to SpElExpression during its evaluation. For our example we will use the below pojo class Employee package spel.package20; public class Employee { private int id; private String name; private int salary; public Employee(int id, String name, int salary)…… Continue reading Making Java objects available during sqel expression evaluation