Thursday, September 07, 2017
Merge and Paginate PDF files using iText 5
In this post we will see a way to merge multiple PDF files while adding page numbers at the bottom of each page in the format Page 1 of 10. The following steps give a brief description of the steps used to merge and add page number to the merged PDF.
Wednesday, September 06, 2017
Merge PDF files using iText 5
This is an example code for a simple PDF merge using iText 5. We use three
InputStreams in a List as input and merged file is written to the file system.
Monday, September 04, 2017
WatchService to monitor Directories for changes
There a many scenarios where you would like to monitor a directory for new files, or changes to existing files or deleted files. Some of the use cases are
- Files will be dropped into a directory by a third party which have to be processed by your application
- A file editor which monitors the directory to make sure the files currently being edited are not modified by another concurrent user.
- You want to start a build and deploy code whenever a source file is changed (In an enterprise application, this is usually done in a source control in conjunction with a tool like Jenkins).
java.nio.file.WatchService provides a scalable solution to monitor directory for any changes. In this post, we will go over the features of the WatchService service and a simple example for how to monitor a directory for changes and print the name of the file that was affected.
Friday, September 01, 2017
Directory Listing in Java
This post provides a examples of a few ways to list contents of a directory in Java. A couple of examples of how to recursively traverse a directory are also provided. Finally we will see the use of
Files.walk() and Files.find() introduced in Java 8, which makes directory traversal even more simple.Thursday, August 31, 2017
Java 8 Stream collect()
In Java 8 Streams, the
collect() method is a terminal operation, which can be used collect elements of a stream into a list or group them into a Map etc. collect method takes java.util.stream.Collector as parameter. While you can create your own collector by implementing the java.util.stream.Collector interface, the more common way to instantiate a Collector is through the use of Collectors class. The following examples demonstrate a few ways to use the collect() method with different types of Collectors.
Wednesday, August 30, 2017
Java 8 Streams flatMap()
In Java 8 Stream API,
flatMap() method is an intermediate functions for streams, in that, it will produce a final result but used to apply transformations on the elements of a Stream. It is possible to to chain multiple flatMap() while processing a single stream.
Both map() and flatMap() both can be applied to a Stream<T> and return a Stream<R> or transformed elements, but the main difference is that map() produces one output element for each input element, whereas flatMap() produces any number (0-n) of output elements for each input element. Put simply, when using a map(), the resulting stream would have same number or elements as the input stream, where as it can be different in case of a flatMap(). The following example illustrates the differences the use of flatMap()
Monday, August 28, 2017
Java 8 Streams map()
In Java 8 Streams, map() is an intermediate function that can be used to apply a function to every element of a Stream. A few variations of map() include mapToInt(), mapToLong etc. which return streams of the corresponding types. The following examples show a few ways to use the map() function on streams.
Subscribe to:
Posts (Atom)
Popular Posts
-
This post will describe how to create and deploy a Java Web Application war to Heroku using Heroku CLI. You will need a basic understanding ...
-
Last week, I described how to implement JMS, using a stand-alone client and a Message Driven Bean . In this post and the next, I will descr...
-
In this post we will see how to do an offline install Jenkins and required plugins on a Red Hat Enterprise Linux Server release 7.3. This is...
-
New posts with iText 5.5.12 Following are two new posts for PDF Merge with iText 5.5.12 Merge PDF files using iText 5 Merge and Paginate PDF...
-
Java 8 introduces default static methods that enable you to add new functionality to the interfaces of your libraries and ensure binary comp...
-
In a previous post, I described how to use Quartz scheduler for scheduling . In this post, I describe the configuration changes required for...
-
Redhat Enterprise Linux provides Redhat Developer Toolset , which allows you to install Git. However, it is usually an older version. If you...
-
The previous post described how to implement a JMS messaging client using Spring JMS . This post will describe how to implement the Message ...
-
The previous post described the Strategy pattern in brief. I listed out where and why the strategy pattern may be used. This post describes...
-
When using the Gradle application plugin, Gradle spawns a new JVM on the fly, and does not pass the System Properties or Command-line argume...