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

Loading multiple instances by list of entity ids

From hibernate 5.1 we can load multiple instances of same class type in one shot by using the list of ids. The below code gives an example of this import java.util.List; import org.hibernate.MultiIdentifierLoadAccess; import org.hibernate.Session; import org.hibernate.SessionFactory; import model.Series; public class HibernateDemo { public static void main(String[] args) { SessionFactory sessionFactory = HibernateUtil.createSessionFactory(); Session session… Continue reading Loading multiple instances by list of entity ids

Updating a particular element in JAXB generated xml

Sometimes xml documents are very big and our requirement is to update a particular section of the document. JAXB binder comes to our help. Binder object maintains the mapping between the java object and xml infoset like DOM. Any modification to java object can be synchronized to xml held by binder object and vice versa.… Continue reading Updating a particular element in JAXB generated xml