This post will be a simple introduction to JCache api. For this post and other future post related to JCache, I will be using Ehcache (a tool that provides caching facility). For the below example we need to know about the below terms. 1) CachingProvider 2) CacheManager 3) Cache 4) Configuration CachingProvider –> Represents the…… Continue reading JCache simple example
Month: October 2016
Creating a file archiver in zip format
This post explains how to create file archiver in WinZip format. WinZip is a file archiver and compression tool. Whenever a zip file is created by default the file is compressed and archived together in a single file. We can change the default behaviour (i.e., compression) by setting the level property in ZipOutputStream. The below…… Continue reading Creating a file archiver in zip format
Creating a zip file of a folder with CRC32 checksum
This post explains how to create a zip file of a folder (also containing sub folders) with CRC32 checksum. The below code is similar to the previous post “Creating zip file of a folder” with minor change in main method. The main method code snippet from the previous post as shown below File folder =…… Continue reading Creating a zip file of a folder with CRC32 checksum
Printing json data in a formatted way
This post explains how to print json data in a properly formatted way, whether the destination is console, file etc. For example when the below code prints the json data to a file, the output will be as shown below Initial Code package package11; import java.io.File; import java.io.FileWriter; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; public…… Continue reading Printing json data in a formatted way
Handling json deserialization error
This post explains how to handle errors generated while deserializing the json file. This can be achieved by implementing an interface “DeserializationProblemHandler” provided by jackson framework as shown below UnMarshallingErrorHandler package package1; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; public class UnMarshallingErrorHandler extends DeserializationProblemHandler { @Override public boolean handleUnknownProperty(DeserializationContext ctxt,…… Continue reading Handling json deserialization error