org.jcoderz.commons.connector.file
Interface FsConnection


public interface FsConnection

The File System Connection Interface.


Method Summary
 void close()
          Initiates close of the connection handle at the application level.
 boolean createFile(String file)
          Creates a new, empty file named by the given parameter file if and only if a file with this name does not yet exist.
 String createTempFile()
          Creates an empty file in the default temporary-file directory.
 String createTempFile(String dir)
          Creates an empty file in the supplied dir directory.
 boolean deleteFile(String file)
          Deletes the supplied file or directory file.
 FileInputStream getFileInputStream(String file)
          Returns a FileInputStream instance.
 RandomAccessFile getRandomAccessFile(String file, String mode)
          Returns a random access file.
 boolean isExists(String file)
          Tests whether the givent file or directory file exists.
 String[] listFiles(String dir)
          Returns an array of strings naming the files and directories in the directory dir.
 void moveFile(String src, String dest)
          Moves the file src to dest.
 void renameFile(String from, String to)
          Renames the supplied file from to to.
 String renameToTempFile(String file)
          Renames the as parameter passed file file to a temp file in the default temporary-file directory.
 

Method Detail

close

void close()
           throws ResourceException
Initiates close of the connection handle at the application level. A connection client is required to call this method after the connection is no more in use.

Throws:
ResourceException - thrown if close on a connection handle fails. Any invalid connection close invocation should also throw this exception.

isExists

boolean isExists(String file)
                 throws ResourceException
Tests whether the givent file or directory file exists.

Parameters:
file - The file or directory to be checked.
Returns:
True if and only the givent file or directory file exists; false otherwise.
Throws:
ResourceException - The Security method denies read access to the file or directory file.

deleteFile

boolean deleteFile(String file)
                   throws ResourceException
Deletes the supplied file or directory file.

Parameters:
file - The file or directory to be deleted.
Returns:
if and only if the file or directory is successfully deleted; false otherwise
Throws:
ResourceException - If a security manager does not allow the file to be deleted.

renameFile

void renameFile(String from,
                String to)
                throws ResourceException
Renames the supplied file from to to.

Parameters:
from - The file to be renamed.
to - The new file name.
Throws:
ResourceException - Thrown to indicate that the file from could not be deleted. For example: The Security method denies write access to the file or directory to.

moveFile

void moveFile(String src,
              String dest)
              throws ResourceException
Moves the file src to dest.

Parameters:
src - The file to be moved from.
dest - The file to be moved to.
Throws:
ResourceException - Thrown to indicate that the file src could not be moved to the dest. For example: The Security method denies write access to the file or directory dest.

listFiles

String[] listFiles(String dir)
                   throws ResourceException
Returns an array of strings naming the files and directories in the directory dir.

Parameters:
dir - The directory whose file's list has be retrieved.
Returns:
If the given path dir does not exist or does not denote a directory, then this method returns null. Otherwise returns the list of files in the directory dir.
Throws:
ResourceException - Thrown in error cases.
See Also:
File.list()

getRandomAccessFile

RandomAccessFile getRandomAccessFile(String file,
                                     String mode)
                                     throws ResourceException,
                                            FileNotFoundException
Returns a random access file.

Parameters:
file - The system-dependent filename
mode - The access mode
Returns:
RandomAccessFile instance.
Throws:
ResourceException - thrown in error cases.
FileNotFoundException - if the file exists but is a directory rather than a regular file, or cannot be opened or created for any other reason.

getFileInputStream

FileInputStream getFileInputStream(String file)
                                   throws ResourceException,
                                          FileNotFoundException
Returns a FileInputStream instance.

Parameters:
file - The system-dependent filename
Returns:
FileInputStream instance.
Throws:
ResourceException - thrown in error cases.
FileNotFoundException - If the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.

createTempFile

String createTempFile()
                      throws ResourceException
Creates an empty file in the default temporary-file directory.

Returns:
The name of the created file.
Throws:
ResourceException - If a security manager does not allow a file to be created or a file could not be created for some other reasons.

createTempFile

String createTempFile(String dir)
                      throws ResourceException
Creates an empty file in the supplied dir directory.

Parameters:
dir - The parent directory for the file to be created.
Returns:
The name of the created file.
Throws:
ResourceException - If the supplied dir directory does not exist, If a security manager does not allow a file to be created or a file could not be created for some other reasons.

createFile

boolean createFile(String file)
                   throws ResourceException
Creates a new, empty file named by the given parameter file if and only if a file with this name does not yet exist. Any required parent folders will be created if they do not exist yet.

Parameters:
file - The name of the file to be created.
Returns:
true If the file file does not exist and was successfully created; false if the named file already exists.
Throws:
ResourceException - If a security manager does not allow a file to be created or a file could not be created for some other reasons.

renameToTempFile

String renameToTempFile(String file)
                        throws ResourceException
Renames the as parameter passed file file to a temp file in the default temporary-file directory.

Parameters:
file - The name of the file to be reanmed.
Returns:
The name of the temp file.
Throws:
ResourceException - If a security manager does not allow the file to be renamed or a temp file to be created; or if a file could not be renamed for some other reasons.


Copyright 2007 The jCoderZ Project.