Home » Archives for Byron Kiourtzoglou » Page 40

Author Archives: Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.

Add/Subtract Hours from Date with Calendar

In this example we shall show you how to add and substract Hours from a Date with the Calendar class. Using this abstract class we can convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. To add and substract Hours from Date with the Calendar one should perform the following ...

Read More »

Add/Subtract Days from Date with Calendar

This is an example of how to add and subtract Days from a Date using the Calendar, that provides methods to convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. Adding and subtracting Days from a Date using the Calendar implies that you should: Create a new Calendar object, using ...

Read More »

Create zip file from multiple files with ZipOutputStream

With this example we are going to demonstrate how to create a zip file from multiple Files with ZipOutputStream, that implements an output stream filter for writing files in the ZIP file format. In short, to create a zip file from multiple Files with ZipOutputStream you should: Create a FileOutputStream to write to the file with the specified name, that ...

Read More »

Create zip file from directory with ZipOutputStream

In this example we shall show you how to create a zip file from a directory with ZipOutputStream class, that is an output stream filter for writing files in the ZIP file format. To create a zip file from a directory with ZipOutputStream one should perform the following steps: Create a FileOutputStream to write to the file with the specified ...

Read More »

Search file in a zip file

This is an example of how to search a File in a zip file, using the ZipFile class. Searching a File in a zip file implies that you should: Create a new ZipFile and open it for reading. Get the enumeration of the ZipFile entries, with entries() API method of ZipFile and iterate through each one of them. For each ...

Read More »

Calculate CRC-32 checksum of zip entry

With this example we are going to demonstrate how to calculate the CRC-32 checksum of a ZipEntry. In short, to calculate the CRC-32 checksum of a ZipEntry you should: Create a new ZipFile and open it for reading. Get the Enumeration of the ZipFile entries, with entries() API method of ZipFile and iterate through each one of them. For each ...

Read More »

Calculate CRC32 checksum for byte array

In this example we shall show you how to calculate the CRC32 Checksum of a byte array. To calculate the CRC32 checksum of a byte array one should perform the following steps: Get the byte array of a String, using getBytes() API method of String. Create a new Checksum object, that represents a data checksum. Update the current checksum with ...

Read More »

Compress – Decompress files example

This is an example of how to zip and unzip a file. We have implemented the FileCompressionUtil class, that consists of four methods, that zip and unzip a file with or without a checksum. The first method zipFilesInPath(final String zipFileName, final String filePath) zips a file in a specific path. The method creates a ZipOutputStream, using a FileOutputStream, with the ...

Read More »

Synchronous Queue example to execute commands

private BlockingQueue workQueue = new LinkedBlockingQueue(); private Map commandQueueMap = new ConcurrentHashMap(); public SynchronousQueue addCommand(Command command) { SynchronousQueue queue = new SynchronousQueue(); commandQueueMap.put(command, queue); workQueue.offer(command); return queue; } public Object call() throws Exception { try { Command command = workQueue.take(); Result result = command.execute(); SynchronousQueue queue = commandQueueMap.get(command); queue.offer(result); return null; } catch (InterruptedException e) { throw new WorkException(e); } ...

Read More »

Blocking Queue example to execute commands

import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; private BlockingQueue<Command> workQueue = new LinkedBlockingQueue<Command>(); public void addCommand(Command command) { workQueue.offer(command); } public Object call() throws Exception { try { Command command = workQueue.take(); command.execute(); } catch (InterruptedException e) { throw new WorkException(e); } } Related Article: Java Concurrency Tutorial – Blocking Queues Reference: Java Concurrency Part 5 – Blocking Queues from our JCG partners ...

Read More »