j2ee.io
Class File

java.lang.Object
  extended by java.io.File
      extended by j2ee.io.File
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class File
extends java.io.File

This version of the File class that inherits from the java.io.File class is designed specially to let user's at the J2EEPS at CERN use and write to files stored at their local user area at DFS.

For this to work, the user has to have a file named dfs.properties inside his/hers war-file, where the following keys has to be present

If this information is present and valid, each time the user creates an object of this class, it will be searched for the same file at the DFS location, and the user can call all the methods available in this class and will manipulate the file at DFS.

See Also:
Serialized Form

Field Summary
private  org.apache.commons.httpclient.HttpsURL hrl
           
private  java.lang.String location
           
private  java.lang.String password
           
private  java.lang.String path
           
private  java.lang.String username
           
private  org.apache.webdav.lib.WebdavResource wdr
           
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
File(File parent, java.lang.String child)
          A constructor that creates the file/directory specified with parent and child string in the temporary directory locally at the J2EEPS container in question.
File(java.lang.String pathName)
          A constructor that creates the file/directory specified in the temporary directory locally at the J2EEPS container in question.
File(java.lang.String parent, java.lang.String child)
          A constructor that creates the file/directory specified with parent and child string in the temporary directory locally at the J2EEPS container in question.
 
Method Summary
private  boolean createDirectory(java.lang.String s)
          This method creates the directory specified by the input string at DFS, if it already doesn't exist
 boolean createNewFile()
          Currently not implemented
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix)
          Not implemented
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory)
          Not implemented
 boolean delete()
          Deletes the file or directory denoted by this abstract pathname.
private  boolean deleteFile(java.lang.String path)
          This method deletes the file at DFS.
 void deleteOnExit()
          This method is not possible to implement correctly, as there is no indication to DFS about when the Java virtual machine terminates.
 boolean exists()
          Tests whether the file or directory denoted by this abstract pathname exists at DFS.
private  boolean existsAtDFS(java.lang.String path)
          Checks if the specified input path exists at DFS
 java.io.File getAbsoluteFile()
          Returns the absolute form of this abstract pathname.
 java.lang.String getAbsolutePath()
          Returns the absolute pathname string of this abstract pathname.
 java.io.File getCanonicalFile()
          Returns the canonical form of this abstract pathname.
 java.lang.String getCanonicalPath()
          If a connection to DFS is possible, this will return the same as this.getAbsolutePath().
private  void getDirectory(java.lang.String[] paths)
          This method creates the directory with all parents specified in the input array, both locally and at DFS
private  void getFile(java.lang.String[] paths)
          This method takes the file from the DFS location and copies it to the temporary directory locally at the J2EEPS server, for there to be further accessed/written to from the user's application
private  boolean getLocationInfo()
          Checks if it can find a dfs.properties file in the user's directory.
 java.lang.String getName()
          Returns the name of the file or directory denoted by this abstract pathname.
 java.lang.String getParent()
          Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
 java.io.File getParentFile()
          Returns the file object for abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
 java.lang.String getPath()
          Converts this abstract pathname into a pathname string.
 boolean isAbsolute()
          Tests whether this abstract pathname is absolute.
 boolean isDirectory()
          Tests whether the file denoted by this abstract pathname is a directory.
 boolean isFile()
          Tests whether the file denoted by this abstract pathname is a normal file.
 java.lang.String[] list()
          Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
 java.lang.String[] list(java.io.FilenameFilter filter)
          Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
 File[] listFiles()
          Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
 File[] listFiles(java.io.FileFilter filter)
          Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
 File[] listFiles(java.io.FilenameFilter filter)
          Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
static File[] listRoots()
          Not implemented
 boolean mkdir()
          It the file in question is a directory, this method creates the directory at DFS if DFS location information is available and valid.
 boolean mkdirs()
          This method creates the directory that is denoted by this abstract pathname both locally and at DFS if valid DFS location information is available.
private  java.lang.String parseLocation(java.lang.String s)
          Helper method that ensures that the input does not start or end with a "/".
 boolean renameTo(java.io.File dest)
          Not implemented
private  boolean setDFSConnection(java.lang.String location)
          This method sets the DFS connection according to the specified input.
 java.net.URI toURI()
          Not implemented, always returns null
 java.net.URL toURL()
          Not implmenented, always returns null
private  java.lang.String trim(java.lang.String s)
          Helper method that removes separators (normally "/"'s) from the end and the beginning of the input string, if they exist
private  java.lang.String trimFirst(java.lang.String s)
          Helper method that removes the separator (normally "/") if the input string starts with it
private  java.lang.String[] vectorize(java.lang.String input)
          Helper method that splits the input around the separator defined (usually "/")
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, equals, hashCode, isHidden, lastModified, length, setLastModified, setReadOnly, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

location

private java.lang.String location

username

private java.lang.String username

password

private java.lang.String password

wdr

private org.apache.webdav.lib.WebdavResource wdr

hrl

private org.apache.commons.httpclient.HttpsURL hrl

path

private java.lang.String path
Constructor Detail

File

public File(java.lang.String pathName)

A constructor that creates the file/directory specified in the temporary directory locally at the J2EEPS container in question.

If it can find information about user credentials for DFS, it tries to retrieve the file and put it in the temporary directory for it to be further accessed

If the input is a directory (e.g. ends with /) it will create the directory at DFS if user credentials is available

The method uses the constructor of the superclass and adds the temporary directory path directly when calling the superclass constructor

Parameters:
pathName - The path for the file/directory

File

public File(java.lang.String parent,
            java.lang.String child)

A constructor that creates the file/directory specified with parent and child string in the temporary directory locally at the J2EEPS container in question.

If it can find information about user credentials for DFS, it tries to retrieve the file and put it in the temporary directory for it to be further accessed

If the input is a directory (e.g. ends with /) it will create the directory at DFS if user credentials is available

The method uses the constructor of the superclass and adds the temporary directory path directly when calling the superclass constructor

Parameters:
parent - The path for the parent of the file
child - The name of the child file

File

public File(File parent,
            java.lang.String child)

A constructor that creates the file/directory specified with parent and child string in the temporary directory locally at the J2EEPS container in question.

If it can find information about user credentials for DFS, it tries to retrieve the file and put it in the temporary directory for it to be further accessed

If the input is a directory (e.g. ends with /) it will create the directory at DFS if user credentials is available

The method uses the constructor of the superclass and adds the temporary directory path directly when calling the superclass constructor

Parameters:
parent - The parent file object
child - The name of the child file
Method Detail

getDirectory

private void getDirectory(java.lang.String[] paths)

This method creates the directory with all parents specified in the input array, both locally and at DFS

It uses the method File.createDirectory() to create the directories at DFS. Is only used if a valid connection to DFS can be established

Parameters:
paths - - The String array with the directory itself and all parents that should be created

toURL

public java.net.URL toURL()

Not implmenented, always returns null

Overrides:
toURL in class java.io.File
Returns:
null

toURI

public java.net.URI toURI()

Not implemented, always returns null

Overrides:
toURI in class java.io.File
Returns:
null

getFile

private void getFile(java.lang.String[] paths)

This method takes the file from the DFS location and copies it to the temporary directory locally at the J2EEPS server, for there to be further accessed/written to from the user's application

Parameters:
paths - - The String array with all the path information for the parents of the file and the file itself

parseLocation

private java.lang.String parseLocation(java.lang.String s)

Helper method that ensures that the input does not start or end with a "/". Is used to ensure conformity when treating location strings in the class

Parameters:
s - - The string to be checked for starting or ending "/"'s
Returns:
- The parsed string

getLocationInfo

private boolean getLocationInfo()

Checks if it can find a dfs.properties file in the user's directory.

Returns:
true if a connection is possible to DFS, false otherwise

vectorize

private java.lang.String[] vectorize(java.lang.String input)

Helper method that splits the input around the separator defined (usually "/")

Is used to give an array of parent directories and the directory/file itself

Parameters:
input - - The string to be split
Returns:
A String array with the parent directories and the directory/file itself

delete

public boolean delete()

Deletes the file or directory denoted by this abstract pathname. Should be used with care

Overrides:
delete in class java.io.File
Returns:
true if and only if the file or directory is successfully deleted; false otherwise

getAbsolutePath

public java.lang.String getAbsolutePath()

Returns the absolute pathname string of this abstract pathname.

If a connection to DFS is possible, it will remove the temporary directory of the J2EEPS container from the path, and just show the DFS part from the user's location directory in dfs.properties.

Otherwise it will return the superclass method

Overrides:
getAbsolutePath in class java.io.File
Returns:
The absolute pathname string denoting the same file or directory as this abstract pathname

deleteOnExit

public void deleteOnExit()

This method is not possible to implement correctly, as there is no indication to DFS about when the Java virtual machine terminates.

It will, if called, call the superclass method and the file will be deleted locally on termination as described for the superclass constructor (but no deletion at DFS)

Overrides:
deleteOnExit in class java.io.File

deleteFile

private boolean deleteFile(java.lang.String path)

This method deletes the file at DFS. It is used by the File.delete() method

Parameters:
path - - The path to the file/directory that should be deleted
Returns:
true if the file/directory was deleted, false otherwise

setDFSConnection

private boolean setDFSConnection(java.lang.String location)

This method sets the DFS connection according to the specified input. It does not check if this is a valid location, that has to be done after by trying to create the WebdavResource connection

Parameters:
location - - the DFS location
Returns:
true if the connection is okay, false otherwise

getCanonicalPath

public java.lang.String getCanonicalPath()
                                  throws java.io.IOException

If a connection to DFS is possible, this will return the same as this.getAbsolutePath(). If not, it returns the result of the superclass method

Overrides:
getCanonicalPath in class java.io.File
Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
java.io.IOException

getParent

public java.lang.String getParent()

Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Overrides:
getParent in class java.io.File
Returns:
The pathname string of the parent directory named by this abstract pathname, or null if this pathname does not name a parent

getParentFile

public java.io.File getParentFile()

Returns the file object for abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Overrides:
getParentFile in class java.io.File
Returns:
The file object of the abstract pathname of this abstract pathname's parent or null if this pathname does not name a parent directory

trimFirst

private java.lang.String trimFirst(java.lang.String s)

Helper method that removes the separator (normally "/") if the input string starts with it

Parameters:
s - - The string to be checked
Returns:
The parsed string, separator removed if the input string started with it

trim

private java.lang.String trim(java.lang.String s)

Helper method that removes separators (normally "/"'s) from the end and the beginning of the input string, if they exist

Parameters:
s - - The input string to be checked
Returns:
The parsed string

getCanonicalFile

public java.io.File getCanonicalFile()
                              throws java.io.IOException

Returns the canonical form of this abstract pathname. Equivalent to new File(this.getCanonicalPath()()).

Overrides:
getCanonicalFile in class java.io.File
Returns:
The file created from the canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
java.io.IOException

createNewFile

public boolean createNewFile()

Currently not implemented

Overrides:
createNewFile in class java.io.File
Returns:
false

existsAtDFS

private boolean existsAtDFS(java.lang.String path)

Checks if the specified input path exists at DFS

Parameters:
path - - The path to be checked for existance
Returns:
true if the path is a valid (existing) location at DFS, false otherwise

exists

public boolean exists()

Tests whether the file or directory denoted by this abstract pathname exists at DFS. If no DFS location information is available it calls the suprclass method

Overrides:
exists in class java.io.File
Returns:
true if the file/directory exists at DFS if DFS location information is available and correct, the return value of the superclass method if not

getAbsoluteFile

public java.io.File getAbsoluteFile()

Returns the absolute form of this abstract pathname. Equivalent to new File(this.getAbsolutePath()())

Overrides:
getAbsoluteFile in class java.io.File
Returns:
The File object created from the absolute abstract pathname denoting the same file or directory as this abstract pathname

getPath

public java.lang.String getPath()

Converts this abstract pathname into a pathname string. The resulting string uses the default name-separator character to separate the names in the name sequence.

Overrides:
getPath in class java.io.File
Returns:
The string form of this abstract pathname

isDirectory

public boolean isDirectory()

Tests whether the file denoted by this abstract pathname is a directory. If information about connection to DFS is available it checks whether this pathname is a directory at DFS, otherwise the superclass method is returned

Overrides:
isDirectory in class java.io.File
Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise

isFile

public boolean isFile()

Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.

Overrides:
isFile in class java.io.File
Returns:
if DFS connection is available: true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise. if no connection available: the superclass method return value

list

public java.lang.String[] list()

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.

If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of strings is returned, one for each file or directory in the directory. Names denoting the directory itself and the directory's parent directory are not included in the result. Each string is a file name rather than a complete path.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Overrides:
list in class java.io.File
Returns:
An array of strings naming the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs

list

public java.lang.String[] list(java.io.FilenameFilter filter)

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the list() method, except that the strings in the returned array must satisfy the filter. If the given filter is null then all names are accepted. Otherwise, a name satisfies the filter if and only if the value true results when the FilenameFilter.accept(java.io.File, java.lang.String) method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.

Overrides:
list in class java.io.File
Parameters:
filter - - A filename filter
Returns:
An array of strings naming the files and directories in the directory denoted by this abstract pathname that were accepted by the given filter. The array will be empty if the directory is empty or if no names were accepted by the filter. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

listFiles

public File[] listFiles()

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Overrides:
listFiles in class java.io.File
Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

listFiles

public File[] listFiles(java.io.FileFilter filter)

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the listFiles() method, except that the pathnames in the returned array must satisfy the filter. If the given filter is null then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the value true results when the FileFilter.accept(java.io.File, java.lang.String) method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.

Overrides:
listFiles in class java.io.File
Parameters:
filter - - A filename filter
Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

listFiles

public File[] listFiles(java.io.FilenameFilter filter)

Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter. The behavior of this method is the same as that of the listFiles() method, except that the pathnames in the returned array must satisfy the filter. If the given filter is null then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the value true results when the FileNameFilter.accept(java.io.File, java.lang.String) method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.

Overrides:
listFiles in class java.io.File
Parameters:
filter - - A filename filter
Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

mkdir

public boolean mkdir()

It the file in question is a directory, this method creates the directory at DFS if DFS location information is available and valid. If parent directories does not exist, this method will return false (use mkdirs() instead to simultaneously create parent directories)

If no valid DFS location information is available, the superclass method is called and the directory can be created locally

Overrides:
mkdir in class java.io.File
Returns:
true if and only if the directory was created; false otherwise

mkdirs

public boolean mkdirs()

This method creates the directory that is denoted by this abstract pathname both locally and at DFS if valid DFS location information is available. If not, it uses the superclass method to create the directory and any non-existent parent directories

Overrides:
mkdirs in class java.io.File
Returns:
true if and only if the directory was created, along with all necessary parent directories; false otherwise

createDirectory

private boolean createDirectory(java.lang.String s)

This method creates the directory specified by the input string at DFS, if it already doesn't exist

Parameters:
s - - The path to the directory that should be created
Returns:
true if the directory was created or already existed, false otherwise

renameTo

public boolean renameTo(java.io.File dest)

Not implemented

Overrides:
renameTo in class java.io.File
Returns:
false

getName

public java.lang.String getName()

Returns the name of the file or directory denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.

Overrides:
getName in class java.io.File
Returns:
The name of the file or directory denoted by this abstract pathname, or the empty string if this pathname's name sequence is empty

listRoots

public static File[] listRoots()

Not implemented

Returns:
null;

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix,
                                          java.io.File directory)

Not implemented

Returns:
null

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix)

Not implemented

Returns:
null

isAbsolute

public boolean isAbsolute()

Tests whether this abstract pathname is absolute. If a connection to DFS is valid, it will never be. Otherwise, the superclass method is used

Overrides:
isAbsolute in class java.io.File
Returns:
false if a valid DFS connection is available, the superclass method return value if not