org.sitemesh.offline.directory
Class InMemoryDirectory

java.lang.Object
  extended by org.sitemesh.offline.directory.InMemoryDirectory
All Implemented Interfaces:
Directory

public class InMemoryDirectory
extends Object
implements Directory

Simple Directory implementation that stores contents in memory.

Can be useful for testing or providing an intermediate input/output for processing.

Author:
Joe Walnes

Constructor Summary
InMemoryDirectory()
           
InMemoryDirectory(Charset encoding)
           
 
Method Summary
 void copy(String path, Directory destinationDirectory, String destinationPath)
          Copy a file from this directory to another location.
 List<String> listAllFilePaths()
          Get a list of all file paths (relative to the Directory).
 CharBuffer load(String path)
          Load the contents from a file.
 void load(String path, WritableByteChannel channelToWriteTo)
          Load binary data.
 void save(String path, CharBuffer contents)
          Save the contents to a file, overwriting any existing content.
 void save(String path, ReadableByteChannel channelToReadFrom, int length)
          Save binary data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryDirectory

public InMemoryDirectory()

InMemoryDirectory

public InMemoryDirectory(Charset encoding)
Method Detail

load

public CharBuffer load(String path)
                throws IOException
Description copied from interface: Directory
Load the contents from a file.

Specified by:
load in interface Directory
Throws:
IOException

save

public void save(String path,
                 CharBuffer contents)
          throws IOException
Description copied from interface: Directory
Save the contents to a file, overwriting any existing content.

Specified by:
save in interface Directory
Throws:
IOException

listAllFilePaths

public List<String> listAllFilePaths()
                              throws IOException
Description copied from interface: Directory
Get a list of all file paths (relative to the Directory). Excludes directories.

Specified by:
listAllFilePaths in interface Directory
Throws:
IOException

load

public void load(String path,
                 WritableByteChannel channelToWriteTo)
          throws IOException
Description copied from interface: Directory
Load binary data.

Specified by:
load in interface Directory
Throws:
IOException

save

public void save(String path,
                 ReadableByteChannel channelToReadFrom,
                 int length)
          throws IOException
Description copied from interface: Directory
Save binary data.

Specified by:
save in interface Directory
Throws:
IOException

copy

public void copy(String path,
                 Directory destinationDirectory,
                 String destinationPath)
          throws IOException
Description copied from interface: Directory
Copy a file from this directory to another location. Will copy raw bytes so can deal with binary data (e.g. images).

Specified by:
copy in interface Directory
Parameters:
path - Path of file to copy (from this Directory)
destinationDirectory - Target directory (may be this)
destinationPath - Path under target directory.
Throws:
IOException


Copyright © 2011. All Rights Reserved.