String to InputStream conversion

In this post under Apache Commons IO, I will show with example how to convert a String to InputStream. “IOUtils” class in Apache Commons IO framework provides a method named “toInputStream” which converts a String to InputStream. This method takes two arguments1) instance of String class2) Charset type Below is the main class showing how…… Continue reading String to InputStream conversion

Using @Singular with @Builder annotation example

In this post under Lombok I will explain with example the purpose of “@Singular” annotation which is alwayse used with “@Builder” annotation. In previous post under lombok I have explained why we use “@Builder” annotation i.e., to implement builder pattern. So if have below pojo class with “@Builder” annotation at the class level Pojo class…… Continue reading Using @Singular with @Builder annotation example

Getting URL of classpath resource

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