The org.bzdev.util package

The package org.bzdev.util contains a number of 'utility' classes.

The class CopyUtilities contains code for copying files, resources, and objects referenced by URLs to a file, output stream or ZIP stream. Copying to a ZIP stream directly is complicated as for a 'stored' entry, the size of the entry must be known in advance.

The class TemplateProcessor allows a file or output stream to be created given a template accessible via a URL, resource, character array, or Reader. The templates consist of ordinary text and directives that consist of a '$', an open delimiter, a keyword, and a closing delimiter. The keyword is used to look up a replacement (there is a variant to this syntax for iteration and comments). The template processor is initialized with maps that indicate how to handle each directive.

There are several iterator classes:

  • EncapsulatingIterator provides a class that takes an iterator whose values have a type T and maps those values to ones of a different type E. For example, if one has an iterator that provides a sequence of strings and a method whose argument is an iterator that produces a series of string lengths, one can use an EncapsulatingIterator to create an iterator that will generate a sequence of string lengths.
  • FilteringIterator provides an iterator that filters the values provided by a different iterator by removing specified values from the iteration.
  • EnumerationIterator and IteratorEnumeration are essentially inverses of each other: these classes can be used to turn an Iterator into an Enumeration and vice versa. The Iterator interface was added to Java after the Enumeration interface was added, and Iterator is the preferred choice, but existing code that used the Enumeration interface was not changed so applications may have to handle a mixture of the two.
  • CollectionScanner provides an iterator that can iterate over the concatenation of multiple collections.

There are several formatter classes:

  • SafeFormatter extends Formatter by including exception-handling code that will replace formatting directives with "%s" directives as a way of handling errors. It is useful for formatting Exception messages where it is better to recover from a formatting error by doing something sensible rather than throwing another exception. Use of this class can make exception handling more robust.
  • SciFormatter extends the Formatter class by allowing floating point numbers to be printed in scientific notation.
  • VarArgsFormatter works like the usual Formatter class, but has explicit methods for up to 11 formatted arguments. This is intended to simply the use of scripting languages that do not recognize Java's use of variable arguments.

There are a number of miscellaneous classes: