Listening to marshaling events

By subclassing Marshaller.Listener abstract class, we can create listener class which will listen to marshling events. We can add our code if we want to perform some actions before and after marshalling. The Marshaller.Listener class has two methods which can be overridden. By default the methods doesn’t perform any actions. 1) public void beforeMarshal(Object source)… Continue reading Listening to marshaling events

Unzipping a zip file and checking for data integrity

This post explains how to unzip a zip file and check whether data were correctly extracted. package ZipDemo; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.CRC32; import java.util.zip.CheckedInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class ZipDemo6 { public static void main(String[] args) throws FileNotFoundException, IOException { String destination = “E:\\Projects\\JavaProjects\\JavaConcepts\\WorkFolder\\Folder1”;… Continue reading Unzipping a zip file and checking for data integrity

Unzipping a zip file

This post explains how to unzip a zip file. package ZipDemo; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class ZipDemo3 { public static void main(String[] args) throws FileNotFoundException, IOException { String destination = “E:\\Projects\\JavaProjects\\JavaConcepts\\WorkFolder\\Folder1”; try (ZipFile zipFile = new ZipFile(“E:\\Projects\\JavaProjects\\JavaConcepts\\WorkFolder\\Folder1.zip”)){ File folder = new File(destination);… Continue reading Unzipping a zip file

Creating a zip file of a folder

This post explains how to create a zip file of a folder (also containing sub folders) The below image shows the hierarchy of the folder package ZipDemo; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ZipDemo2 { private File startingFolder; public ZipDemo2(File startingFolder)… Continue reading Creating a zip file of a folder

Exploring a zip file

This post explains how to explore a zip file. Main Code package ZipDemo; import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class ZipDemo1 { public static void main(String[] args) { try (ZipFile zipFile = new ZipFile(“E:\\Projects\\JavaProjects\\JavaConcepts\\WorkFolder\\Folder1.zip”)){ Enumeration entries = zipFile.entries(); for (Enumeration e = entries; e.hasMoreElements();) { ZipEntry entry = e.nextElement(); System.out.println(entry.getName()); } }… Continue reading Exploring a zip file

Programmatically generating schema for java classes

This post will explain how to generate schema files for java classes programmatically. The schema is generated by an instance of JAXBContext. In addition to JAXBContext we also need SchemaOutputResolver for this purpose. The SchemaOutputResolver class is an abstract class so we need to create a new class extending SchemaOutputResolver as shown below. package JAXB;… Continue reading Programmatically generating schema for java classes