SourceForge.net Logo

Table of Content

Cotta Convention

Based on the “Thoughts behind Cotta”, Cotta is designed to match the common expectations for file operations:

API JavaDoc should only be used for visitors to take a peek at what is inside. Please do provide any feedbacks on any cases where you find them useful than this document.

File Operations

Cotta offers three levels of flexibility for file operations to fit different development needs.

Save and Load

This is used simply for saving and loading text contents.

file.save("content");
ensure.that(file.load()).eq("content");

Or:

TFile file = ...
file.open(new LineProcessor() {
  public void process(String line) {
    System.out.println("Read line: " + line);
  }
});

Managed Resource

All input or output resources created will be tracked and closed automatically, even upon exception. This is similar to the design of Spring template and Ruby file I/O. All exceptions are wrapped in TIoException.

TFile file = ...
file.open(new FileIoProcessor() {
  public void process(FileIoResource io) throws IOException {
    PrintWriter printer = io.printWriter();
    printer.println("line one");
    printer.println("line two");
  }
});

I/O Factory

An I/O factory that does not more than allowing the creations of common I/O streams, reader/writer, printer with just one method call.

TFile file = ...
PrintWriter printer = file.io().printWriter();
try {
  printer.println("line one");
  printer.println("line two");
} catch (IOException e) {
  // ... exception handling code here
} finally {
  printer.close();
}

File Systems

PhysicalFileSystem

The wrapper of Java file operations. This is the default file system that TFileFactory uses.

InMemoryFileSystem

This is used mainly for testing by replacing the FileSystem. InMemoryFileSystem also treat the current directory as a unique location to prevent the bug that caused by the uncertainty of current working directory. You can also configure the InMemoryFileSystem to have different path separator or listing order

ZipFileSystem

A read-only file system that allows archive file browsing.

FtpFileSystem

A file system as a FTP client.

ControlledFileSystem and CatastrophicFileSystem

These are wrapper classes used to control the file system read and writer operations. CatastrophicFileSystem is specially designed to test the case of file system failure or file lock.

Utilities

Cotta also contains a small set of useful utilities.