Miscellaneous utilities for file management.

This package complements the standard Java file handling facilities and apache's {@link org.apache.commons.io.IOUtils}. These include:

In addition to utilities, the package makes available a recommended design pattern for handling streams safely via the supporting class {@link org.marketcetera.util.file.CloseableRegistry}. When a series of streams need to be opened and eventually closed, it is important that such closures takes place in a timely fashion via explicit calls to close(). This must happen even if an exception interrupts normal processing, to ensure that the operating system does not maintain locks on unused files or uses up file descriptors. Here is the recommended approach for handling stream closure:

CloseableRegistry r=new CloseableRegistry();
try {
  ByteArrayOutputStream byteArray=new ByteArrayOutputStream();
  r.register(byteArray);
  PrintStream printStream=new PrintStream(byteArray);
  r.register(printStream);
  ... use printStream
} finally {
  r.close();
}

Many of the above utilities recognize sentinel values as input or output file names, such as :stdin: for standard input; the complete set of such special names is the constants of {@link org.marketcetera.util.file.SpecialNames}.