Package org.marketcetera.util.file
Miscellaneous utilities for file management.
This package complements the standard Java file handling facilities
and apache's IOUtils. These include:
The
CopyBytesUtils,CopyCharsUtils, andCopyCharsUnicodeUtilsclasses provide utilities for copying data between files, streams, and memory, in various combinations.FileTypeoffers symbolic link detection and file typing, in the minimal fashion possible within the platform-independent Java.SmartLinksDirectoryWalkeroffers recursive file tree traversal andDeleteroffers tree deletion; both are sensitive to symbolic links.
In addition to utilities, the package makes available a recommended
design pattern for handling streams safely via the supporting class
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 SpecialNames.
-
Interface Summary Interface Description Messages The internationalization constants used by this package.SpecialNames Special names used to denote standard streams or operations on regular files. -
Class Summary Class Description CloseableRegistry A registry ofCloseableinstances.CopyBytesUtils Utilities for copying binary data.CopyCharsUnicodeUtils Utilities for copying textual data, with Unicode BOM support.CopyCharsUtils Utilities for copying textual data, in the default JVM charset.Deleter Deletes a file or directory recursively.Deleter.RecursiveDeleter ASmartLinksDirectoryWalkerthat does not follow symbolic links, and deletes all files it traverses.InputStreamWrapper A wrapped input stream.OutputStreamWrapper A wrapped output stream.ReaderWrapper A wrapped reader.SmartLinksDirectoryWalker ADirectoryWalkerwhich provides convenience methods to initiate traversal, and (optionally) does not follow symbolic links.WriterWrapper A wrapped writer. -
Enum Summary Enum Description FileType A file type.