Home » Tag Archives: util

Tag Archives: util

Search files in a directory using FutureTask example

In this example we shall show you how to search files in a directory using FutureTask. We have implemented a Class called MatchCounter, that implements the Callable Interface. It is a task that counts the files in a directory and its subdirectories that contain a given keyword. The basics of the example are shown below: The example’s task, MatchCounter is ...

Read More »

ResourceBundle for I18N messages example

With this example we are going to demonstrate how to use the ResourceBundle for I18N messages. ResourceBundle can be used to provide us with locale-specific resources. In short, to use the ResourceBundle for I18N messages you should: Load resource bundle for locale Locale.US, with the getBundle(String baseName, Locale locale) API method of the ResourceBundle and then the getString(String key) API ...

Read More »

Write JAR file Manifest to file

This is an example of how to write a JAR file Manifest to a file. A JAR file is essentially a zip file that contains an optional META-INF directory. In this directory there is a Manifest, that is used to specify meta-information about the jar file and its entries. Writing a JAR file’s Manifest to a file implies that you ...

Read More »

List entries of JAR file Manifest

In this example we shall show you how to list entries of a JAR file Manifest. The manifest is a special file that contains information about the files packaged in a JAR file. To list the entries of a JAR file Manifest one should perform the following steps: Create a new JarFile to read from the specified file. Get the ...

Read More »

Create Manifest for JAR File

With this example we are going to demonstrate how to create a Manifest for a JAR File. In short, to create a Manifest for a JAR File you should: Create a FileInputStream by opening a connection to an actual file. Create a new Manifest from the specified input stream. Invoke the getMainAttributes() API method of the Manifest to get the ...

Read More »

Check if message is loggable

This is an example of how to check if a message is loggable. We are going to use a Logger with logging.Level set to WARNING and then log messages in different levels, in order to check if they are loggable. To do so, we have to: Create an instance of Logger, with the getLogger(String name) API method, using as parameter ...

Read More »

Compare Logger Level

In this example we shall show you how to compare Logger Level. The logging Level is used to control logging output. Level objects, such as SEVERE, WARNING and INFO are ordered and specified by ordered integers, so in order to compare them, one should perform the following steps: Use three Level constants. Compare the intValues of each Level constant with ...

Read More »

Prevent the logger send log messages to its parent logger

With this example we are going to demonstrate how to prevent the logger from sending log messages to its parent logger. When a Logger is used, it keeps track of a parent Logger, which is its nearest existing ancestor in the Logger namespace. By default, the logger publishes to its parent’s Handler. To prevent the logger from sending log messages ...

Read More »

Conditional logging

This is an example of how to use Conditional logging. Using conditional logging in a Class means that we check the Level for which the Logger is enabled before we log a message to that level. We have implemented a Class that uses a logger. The Class consists of a simple method that uses the logger to log messages after ...

Read More »

Use Logger MemoryHandler class

In this example we shall show you how to use the Logger MemoryHandler class. The MemoryHandler is a Handler that buffers requests in a circular buffer in memory. To use the MemoryHandler of a logger one should perform the following steps: Create a Logger instance, with the getLogger(String name) API method of the Logger. Initialize a FileHandler to write to ...

Read More »