com.groovemanager.core
Class FileManager

java.lang.Object
  extended by com.groovemanager.core.FileManager

public abstract class FileManager
extends java.lang.Object


Field Summary
 java.lang.String CONFIG_PATH
          The Path, where Configuration Files Should be stored
static FileManager DEFAULT_FILE_MANAGER
          The default FileManager instance
 java.lang.String EXT_PATH
          The Path, where Extensions for this Application should be stored
 java.lang.String ROOT_PATH
          The Root-Path of the Application´s Ressources
 java.lang.String TEMP_PATH
          The Path, where Temporary Files Should be stored
 
Constructor Summary
protected FileManager()
          Constructs a new FileManager instance, tries to create the different paths if they don't exist and adds the EXT_PATH to the java.ext.dirs and java.library.path system properties.
 
Method Summary
static java.lang.String convertPath(java.lang.String path)
          Converts a given path with Unix slashes "/" to the system dependend path
private static FileManager createDefault()
          Create the default FileManager instance
 java.lang.String getConfigPath(java.lang.String path)
          Get an absolute path from a given String containing the relative path to the CONFIG directory.
static FileManager getDefault()
          Get the default File Manager.
static java.lang.String getExtension(java.io.File f)
          Extracts the extension (e.g.
static java.lang.String getNameWithoutExtension(java.io.File f)
          Get the name of a file without its extension.
static java.io.File getParallelFile(java.io.File source, java.lang.String extension)
          Returns a File object with the name of the source file with an added additional extension
 java.lang.String getRootPath(java.lang.String path)
          Get an absolute path from a given String containing the relative path to the ROOT directory.
 java.lang.String[] listDirsRoot(java.lang.String directory)
          List all directories in a directory relative to the ROOT directory
static java.nio.MappedByteBuffer mapByteContent(java.io.File f)
          Maps a whole file into memory in Read-Only mode
static java.nio.MappedByteBuffer mapByteContent(java.io.File f, java.nio.channels.FileChannel.MapMode mapMode)
          Maps a whole file into memory in the given MapMode
static java.nio.MappedByteBuffer mapByteContent(java.io.File f, long position, long length)
          Maps part of a file into memory in Read-Only mode
static java.nio.MappedByteBuffer mapByteContent(java.io.File f, long position, long length, java.nio.channels.FileChannel.MapMode mapMode)
          Maps part of a file into memory in the given MapMode
protected abstract  void setErrorHandler()
          Set the default error handler This method will be called from within the Constructor and can be overridden by subclasses to set another error
protected abstract  java.lang.String tellConfigPath()
          Tell the Config path of an application under which the configuration files should be stored.
protected abstract  java.lang.String tellExtPath()
          Tell the Extension path of an application under which the extension files lie.
protected abstract  java.lang.String tellRootPath()
          Tell the Root path of an application under which the ressource files lie.
protected abstract  java.lang.String tellTempPath()
          Tell the Temporary path under which temp files should be stored.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONFIG_PATH

public final java.lang.String CONFIG_PATH
The Path, where Configuration Files Should be stored


DEFAULT_FILE_MANAGER

public static final FileManager DEFAULT_FILE_MANAGER
The default FileManager instance


EXT_PATH

public final java.lang.String EXT_PATH
The Path, where Extensions for this Application should be stored


ROOT_PATH

public final java.lang.String ROOT_PATH
The Root-Path of the Application´s Ressources


TEMP_PATH

public final java.lang.String TEMP_PATH
The Path, where Temporary Files Should be stored

Constructor Detail

FileManager

protected FileManager()
Constructs a new FileManager instance, tries to create the different paths if they don't exist and adds the EXT_PATH to the java.ext.dirs and java.library.path system properties.

Method Detail

convertPath

public static java.lang.String convertPath(java.lang.String path)
Converts a given path with Unix slashes "/" to the system dependend path

Parameters:
path - The path using Unix slashes "/"
Returns:
The path using the system dependend file separator

createDefault

private static FileManager createDefault()
Create the default FileManager instance

Returns:
The default FileManager instance

getConfigPath

public java.lang.String getConfigPath(java.lang.String path)
Get an absolute path from a given String containing the relative path to the CONFIG directory.

Parameters:
path - The relative path to the CONFIG directory. The Unix Slash "/" should be used as path separator (will be replaced with the system dependend separator.
Returns:
A File-Instance for the wanted file.

getDefault

public static FileManager getDefault()
Get the default File Manager.

Returns:
The default File Manager. In fact it just returns DEFAULT_FILE_MANAGER

getExtension

public static java.lang.String getExtension(java.io.File f)
Extracts the extension (e.g. "txt") from a file

Parameters:
f - The file
Returns:
The extension without the "."

getNameWithoutExtension

public static java.lang.String getNameWithoutExtension(java.io.File f)
Get the name of a file without its extension. For the file 'Test.txt' this method will return 'Test'.

Parameters:
f - The file
Returns:
The name of the file without any extension

getParallelFile

public static java.io.File getParallelFile(java.io.File source,
                                           java.lang.String extension)
Returns a File object with the name of the source file with an added additional extension

Parameters:
source - The source File
extension - Extension without "." that should be added to the source file´s name
Returns:
The File object with the new name.

getRootPath

public java.lang.String getRootPath(java.lang.String path)
Get an absolute path from a given String containing the relative path to the ROOT directory.

Parameters:
path - The relative path to the ROOT directory. The Unix Slash "/" should be used as path separator (will be replaced with the system dependend separator.
Returns:
The absolute path of the requested File

listDirsRoot

public java.lang.String[] listDirsRoot(java.lang.String directory)
List all directories in a directory relative to the ROOT directory

Parameters:
directory - relative path to the directory The Unix Slash "/" should be used as path separator (will be replaced with the system dependend separator.
Returns:
An array with the names of the found directories

mapByteContent

public static java.nio.MappedByteBuffer mapByteContent(java.io.File f)
                                                throws java.io.IOException
Maps a whole file into memory in Read-Only mode

Parameters:
f - The file to be mapped
Returns:
The MappedByteBuffer
Throws:
java.io.IOException - If an I/O-Error occurs

mapByteContent

public static java.nio.MappedByteBuffer mapByteContent(java.io.File f,
                                                       java.nio.channels.FileChannel.MapMode mapMode)
                                                throws java.io.IOException
Maps a whole file into memory in the given MapMode

Parameters:
f - The file to be mapped
mapMode - The MapMode in which the file should be mapped
Returns:
The MappedByteBuffer
Throws:
java.io.IOException - If an I/O-Error occurs

mapByteContent

public static java.nio.MappedByteBuffer mapByteContent(java.io.File f,
                                                       long position,
                                                       long length)
                                                throws java.io.IOException
Maps part of a file into memory in Read-Only mode

Parameters:
f - The file to be mapped
position - Offset in bytes from the beginning of the file
length - Length in bytes of the region to be mapped
Returns:
The MappedByteBuffer
Throws:
java.io.IOException - If an I/O-Error occurs

mapByteContent

public static java.nio.MappedByteBuffer mapByteContent(java.io.File f,
                                                       long position,
                                                       long length,
                                                       java.nio.channels.FileChannel.MapMode mapMode)
                                                throws java.io.IOException
Maps part of a file into memory in the given MapMode

Parameters:
f - The file to be mapped
position - Offset in bytes from the beginning of the file
length - Length in bytes of the region to be mapped
mapMode - The MapMode in which the file should be mapped
Returns:
The MappedByteBuffer
Throws:
java.io.IOException - If an I/O-Error occurs

setErrorHandler

protected abstract void setErrorHandler()
Set the default error handler This method will be called from within the Constructor and can be overridden by subclasses to set another error


tellConfigPath

protected abstract java.lang.String tellConfigPath()
Tell the Config path of an application under which the configuration files should be stored. In the default FileManager this is the directory given in the user.home System property.

Returns:
The config directory´s absolute path

tellExtPath

protected abstract java.lang.String tellExtPath()
Tell the Extension path of an application under which the extension files lie. This path will be added to the java.ext.dirs System property so that Java extensions can be placed there too. In the default FileManager this is the directory named "ext" unter the current working directory

Returns:
The extension directory´s absolute path. May also be null to indicate that this FileManager doesn't support an extension dir.

tellRootPath

protected abstract java.lang.String tellRootPath()
Tell the Root path of an application under which the ressource files lie. In the default FileManager this is the directory named "root" unter the current working directory

Returns:
The Root directory´s absolute path

tellTempPath

protected abstract java.lang.String tellTempPath()
Tell the Temporary path under which temp files should be stored. In the default FileManager this is the directory given in the java.io.tmpdir System property.

Returns:
The temp directory´s absolute path

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()