corelib.io.files
Class FileSystem

java.lang.Object
  extended by corelib.io.files.FileSystem

public class FileSystem
extends java.lang.Object

This class provides methods to manage the file systems and it's elements (files and directories).

Since:
0.1.0
Author:
Dominique Liard

Constructor Summary
FileSystem()
           
 
Method Summary
static boolean contains(java.lang.String parentPath, java.lang.String childPath)
          Checks if a path is contained into another path.
static void copyFile(java.io.InputStream is, java.lang.String destinationFile)
           
static void copyFile(java.lang.String sourceFile, java.lang.String destinationFile)
          Copies the source file on the destination file.
static void copyFile(java.lang.String sourceFile, java.lang.String destinationFile, boolean overwrite)
          Copies the source file on the destination file.
static void delete(java.lang.String filename)
           
static void delTree(java.lang.String folder)
           
static java.lang.String getCurrentWorkingDirectory()
          Returns the current working directory as string instance.
static long getLastModifiedTime(java.lang.String pathName)
          Returns the last modified time for the considered path.
static boolean isExisting(java.lang.String pathName)
          Check a file (or directory) presence on the FileSystem.
static java.lang.String[] list(java.lang.String folderName)
           
static Folder mkdir(java.lang.String pathName)
          Constructs a new folder on disk.
static Folder mkdirs(java.lang.String pathName)
          Constructs a new folder on disk.
static void moveOrRename(java.lang.String sourceFile, java.lang.String destinationFile)
          Moves or renames the considered file.
static void rmdir(java.lang.String pathName, boolean recursive)
           Remove the specified directory.
static boolean rmFromSnapshot(DirectorySnapshot snapshot)
          Delete elements in a directories structure, only if this element is present in the considered directory snapshot.
static void touch(java.lang.String pathName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystem

public FileSystem()
Method Detail

isExisting

public static boolean isExisting(java.lang.String pathName)
Check a file (or directory) presence on the FileSystem.

Parameters:
pathName - Specify the path to check existance.
Returns:
true if the file exists, false otherwise.

getLastModifiedTime

public static long getLastModifiedTime(java.lang.String pathName)
Returns the last modified time for the considered path.

Parameters:
pathName - The path.
Returns:
The timestamp the the last modified time. You can construct a Date object with this timestamp.

mkdir

public static Folder mkdir(java.lang.String pathName)
                    throws java.io.IOException
Constructs a new folder on disk. If parent folder not exists on disk, an exception will be thrown.

Parameters:
pathName - The new folder path name.
Returns:
The corresponding Folder instance.
Throws:
java.io.IOException - Thrown if the method cannot create the specified folder.

mkdirs

public static Folder mkdirs(java.lang.String pathName)
                     throws java.io.IOException
Constructs a new folder on disk.

Parameters:
pathName - The new folder path name.
Returns:
The corresponding Folder instance.
Throws:
java.io.IOException - Thrown if the method cannot create the specified folder.

rmdir

public static void rmdir(java.lang.String pathName,
                         boolean recursive)
                  throws java.io.IOException

Remove the specified directory. If the directory is not empty and the recursive value equals true, all files and subdirectories are removed. Otherwise, an IOException will be thrown.

Important note: removed files and directories are not moved into the trash. There are definitivly removed. Please, use this method with caution.

Parameters:
pathName - The path of the directory to remove.
recursive - Pass true value if you want recursivly removed all containing files and subdirectories. Pass false otherwize.
Throws:
java.io.IOException - Thrown if the method can't remove the directory structure.

rmFromSnapshot

public static boolean rmFromSnapshot(DirectorySnapshot snapshot)
                              throws DirectorySnapshotException
Delete elements in a directories structure, only if this element is present in the considered directory snapshot.

Parameters:
snapshot - The directory snapshot used to remove files and directories.
Returns:
Returns true if the directory associated to this snapshot is fully removed, false otherwise.
Throws:
java.lang.NullPointerException - Thrown if the specified snapshot is null.
DirectorySnapshotException - Thrown if the specified snapshot cannot be used.
Since:
0.3.7

moveOrRename

public static void moveOrRename(java.lang.String sourceFile,
                                java.lang.String destinationFile)
                         throws java.io.IOException
Moves or renames the considered file.

Parameters:
sourceFile - The originaly file name.
destinationFile - The new file name.
Throws:
java.io.IOException - Thrown if this methods cannot change the file name.

copyFile

public static void copyFile(java.lang.String sourceFile,
                            java.lang.String destinationFile)
                     throws java.io.IOException
Copies the source file on the destination file. If the destination file already exists, an exception is thrown and the file is not copied.

Parameters:
sourceFile - The name of the source file (relative or absolute path names are accepted)
destinationFile - The name of the destination file (relative or absolute path names are accepted)
Throws:
java.io.IOException - Thrown if the file cannot be copied or if the file exists.

copyFile

public static void copyFile(java.lang.String sourceFile,
                            java.lang.String destinationFile,
                            boolean overwrite)
                     throws java.io.IOException
Copies the source file on the destination file. If the overwrite boolean paramater is set to true, and if the destination file exists, it will be overwriten.

Parameters:
sourceFile - The name of the source file (relative or absolute path names are accepted)
destinationFile - The name of the destination file (relative or absolute path names are accepted)
overwrite - Indicates if the destination file can be overwritten (true) or not (false), if file exists.
Throws:
java.io.IOException - Thrown if the file cannot be copied or if the file exists and cannot be overwritten.

copyFile

public static void copyFile(java.io.InputStream is,
                            java.lang.String destinationFile)
                     throws java.io.IOException
Throws:
java.io.IOException

delete

public static void delete(java.lang.String filename)
                   throws java.io.IOException
Throws:
java.io.IOException

delTree

public static void delTree(java.lang.String folder)

touch

public static void touch(java.lang.String pathName)
                  throws java.io.IOException
Throws:
java.io.IOException

list

public static java.lang.String[] list(java.lang.String folderName)

contains

public static boolean contains(java.lang.String parentPath,
                               java.lang.String childPath)
                        throws java.io.IOException
Checks if a path is contained into another path.

Parameters:
parentPath - The parent folder path.
childPath - The child path to check.
Returns:
True if childPath is contained into parentPath
Throws:
java.io.IOException - Thrown if contains method cannot check containment.
java.lang.NullPointerException - Thrown if parentPath or childPath are null.
Since:
0.4

getCurrentWorkingDirectory

public static java.lang.String getCurrentWorkingDirectory()
Returns the current working directory as string instance.

Returns:
The current working directory.


CAUTION: Ellipse is proposed to you in BETA version to allow evaluation of this framework. Infini Software is released from any responsibility for the use of Ellipse Framework.

Copyright 2012 Infini Software - All Rights Reserved.