com.lightdev.lib.filesystem
Class LocalFileSystem

java.lang.Object
  extended by com.lightdev.lib.filesystem.LocalFileSystem
All Implemented Interfaces:
FileSystem

public class LocalFileSystem
extends Object
implements FileSystem

This class implements interface FileSystem for the file system of the machine this class is instantiated on. The implementation relies on the standard Java class java.io.File and wraps its methods into the methods required by interface FileSystem as required and where possible. In addition it implements methods not supported by class java.io.File such as copy, move, etc.

Version:
2, 12.01.2008
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the BSD License, for details see file license.txt in the distribution package of this software
See Also:
FileSystem, File

Field Summary
 
Fields inherited from interface com.lightdev.lib.filesystem.FileSystem
LOCAL_FILE_SYSTEM
 
Constructor Summary
LocalFileSystem()
          create a new instance of class LocalFileSystem
 
Method Summary
 void copy(FileRef[] filesToCopy, FileRef toFolder)
          copy files to a given folder.
 void createFolder(FileRef folder)
          create a new folder
 void delete(FileRef[] filesToDelete)
          delete one or more files
 void extract(FileRef archive, FileRef toFolder)
          extract a given ZIP archive to a given folder
 boolean fileExists(FileRef file)
          determine whether or not a given file exists in this instance of file system
 String getFileSeparator()
          get the string that is used to separate file and folder names in path expressions for the machine this file system refers to
 long getFolderSize(FileRef folder)
          determine the size of a folder in bytes
 FileRef getParentFile(FileRef file)
          get the file that is directly on top of a given file in the file hierarchy of this file system
 FileRef[] getRoots()
          get the root directories of this file system
 String getUrl()
          get the url string of the machine this file system is located
 FileRef[] list(FileRef folder)
          get the files that are contained in a given folder
 void move(FileRef[] filesToMove, FileRef toFolder)
          move one or more files to a given folder.
 void pack(FileRef folder, FileRef archive)
          pack the contents of a given folder into a new ZIP compressed archive
 byte[] read(FileRef file)
          read contents of a file to a byte array in memory
 void rename(FileRef file, String newName)
          rename a file, i.e. change the name of a file but not its location
 void write(FileRef file, byte[] contents)
          write contents of a file from a byte array in memory
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalFileSystem

public LocalFileSystem()
create a new instance of class LocalFileSystem

Method Detail

list

public FileRef[] list(FileRef folder)
get the files that are contained in a given folder

Specified by:
list in interface FileSystem
Parameters:
folder - the directory to get the files for
Returns:
the list of files contained in the given directory
Throws:
Exception

getParentFile

public FileRef getParentFile(FileRef file)
get the file that is directly on top of a given file in the file hierarchy of this file system

Specified by:
getParentFile in interface FileSystem
Parameters:
file - the file to get the parent file for
Returns:
the parent file
Throws:
Exception

getRoots

public FileRef[] getRoots()
get the root directories of this file system

Specified by:
getRoots in interface FileSystem
Returns:
the root directories of this file system
Throws:
Exception

getFileSeparator

public String getFileSeparator()
get the string that is used to separate file and folder names in path expressions for the machine this file system refers to

Specified by:
getFileSeparator in interface FileSystem
Returns:
the separator string
Throws:
Exception

copy

public void copy(FileRef[] filesToCopy,
                 FileRef toFolder)
          throws Exception
copy files to a given folder. Overwrites existing files with the same name inside the target folder.

Specified by:
copy in interface FileSystem
Parameters:
filesToCopy - the files to copy
toFolder - the directory to copy to
Throws:
Exception

rename

public void rename(FileRef file,
                   String newName)
            throws Exception
rename a file, i.e. change the name of a file but not its location

Specified by:
rename in interface FileSystem
Parameters:
file - the file to rename
newName - the new name; just the name, no path
Throws:
Exception

move

public void move(FileRef[] filesToMove,
                 FileRef toFolder)
          throws Exception
move one or more files to a given folder. Overwrites existing files with the same name inside the target folder.

Specified by:
move in interface FileSystem
Parameters:
filesToMove - the the files to move
toFolder - the folder to move to
Throws:
Exception

delete

public void delete(FileRef[] filesToDelete)
            throws Exception
delete one or more files

Specified by:
delete in interface FileSystem
Parameters:
filesToDelete - the list of files to delete
Throws:
Exception

extract

public void extract(FileRef archive,
                    FileRef toFolder)
             throws Exception
extract a given ZIP archive to a given folder

Specified by:
extract in interface FileSystem
Parameters:
archive - the archive to extract
toFolder - the folder to extract the contents of the archive to
Throws:
Exception

pack

public void pack(FileRef folder,
                 FileRef archive)
          throws Exception
pack the contents of a given folder into a new ZIP compressed archive

Specified by:
pack in interface FileSystem
Parameters:
folder - the folder to pack
archive - the archive to create from the given files
Throws:
Exception

createFolder

public void createFolder(FileRef folder)
                  throws Exception
create a new folder

Specified by:
createFolder in interface FileSystem
Parameters:
folder - the folder to create
Throws:
Exception

fileExists

public boolean fileExists(FileRef file)
                   throws Exception
determine whether or not a given file exists in this instance of file system

Specified by:
fileExists in interface FileSystem
Parameters:
file - the file to determine existence for
Returns:
true if the given files exists in this instance of file system, false if not
Throws:
Exception

getFolderSize

public long getFolderSize(FileRef folder)
                   throws Exception
determine the size of a folder in bytes

Specified by:
getFolderSize in interface FileSystem
Parameters:
folder - the folder to determine the size for
Returns:
the size of the folder in bytes
Throws:
Exception

getUrl

public String getUrl()
              throws Exception
get the url string of the machine this file system is located

Specified by:
getUrl in interface FileSystem
Returns:
url string of machine this file system is located
Throws:
Exception

read

public byte[] read(FileRef file)
            throws Exception
read contents of a file to a byte array in memory

Specified by:
read in interface FileSystem
Parameters:
file - reference to the file to read
Returns:
the file contents
Throws:
Exception

write

public void write(FileRef file,
                  byte[] contents)
           throws Exception
write contents of a file from a byte array in memory

Specified by:
write in interface FileSystem
Parameters:
file - reference to the file to write
contents - the contents to write to the referenced file
Throws:
Exception