org.pf.file
Class FileLocator

java.lang.Object
  extended by org.pf.file.FileLocator

public class FileLocator
extends java.lang.Object

This class mainly supports access to files which can be in the normal file directory structure or inside zip archives. The main purpose is to provide methods that transparently treat files the same way whether they are in the normal directory structure or inside archives. The syntax is simply to allow archive names in a path name at any place where a sub-directory name can be.
Examples:

Version:
1.7
Author:
Manfred Duchrow

Field Summary
static java.lang.String TEMP_FILE_PREFIX
           
static java.lang.String TEMP_FILE_SUFFIX
           
 
Method Summary
static FileLocator create(java.io.File file)
          Create a file locator that corresponds to the given file name.
static FileLocator create(java.lang.String filename)
          Create a file locator that corresponds to the given file name.
static FileLocator create(java.net.URL url)
          Create a file locator that corresponds to the given URL.
 java.lang.Exception exception()
          Returns the last exception that occured while using this locator or null, if no exception was thrown at all.
 boolean exists()
          Returns whether or not the file specified by this locator exists.
 java.lang.String getAbsolutePath()
          Returns the full absolute pathname.
 java.io.InputStream getInputStream()
          Returns an opened input stream on the file defined by this locator.
 java.lang.String getOriginalFileName()
          Returns the original (unchanged) filename as it was given to the create method of this locator.
 FileLocator getParent()
          Returns the parent of the file represented by this locator
 java.lang.String getPath()
          Returns the full pathname.
 java.lang.String getStandardizedAbsolutePath()
          Returns the full absolute pathname in a standardized form.
 java.lang.String getStandardizedPath()
          Returns the full pathname in a standardized for.
 boolean isDirectory()
          Returns whether or not the name specified by this locator points to a directory.
 boolean isFile()
          Returns whether or not the name specified by this locator points to a file.
 boolean isInArchive()
          Returns whether or not the file specified by this locator is inside an archive.
 boolean isRemote()
          Returns true if the locator points to a remote file or directory.
 long lastModified()
          Returns the timestamp of when the file was last modified or 0 in any case of error.
 java.io.File realFile()
          Returns the file that contains the data the locator points to.
 long size()
          Returns the size of the file or 0 if it does not exist.
 java.net.URL toURL()
          Returns the name of the file as an URL.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMP_FILE_PREFIX

public static final java.lang.String TEMP_FILE_PREFIX
See Also:
Constant Field Values

TEMP_FILE_SUFFIX

public static final java.lang.String TEMP_FILE_SUFFIX
See Also:
Constant Field Values
Method Detail

getOriginalFileName

public java.lang.String getOriginalFileName()
Returns the original (unchanged) filename as it was given to the create method of this locator.


create

public static FileLocator create(java.io.File file)
Create a file locator that corresponds to the given file name.


create

public static FileLocator create(java.net.URL url)
Create a file locator that corresponds to the given URL. Allowed remote URLs start with either "http://" or "https://" or "jar:http://" or "jar:https://".

Parameters:
url - The url that specifies the file

create

public static FileLocator create(java.lang.String filename)
Create a file locator that corresponds to the given file name. Remote files are also supported for filenames starting with "http://" or "https://".

Parameters:
filename - The name (or URL) that specifies the file

realFile

public java.io.File realFile()
Returns the file that contains the data the locator points to. If the locator points to a normal file in a directory, than this file will be returned. If the locator points to a file inside an archive, the file will be unzipped into the temp directory and this temp file will be returned. If the locator points to a remote file it will be downloaded to the temp directory and this temp file will be returned. If the locator points to a none existing file, this method returns false.


exists

public boolean exists()
Returns whether or not the file specified by this locator exists. If the locator points to a remote file, it will be downloaded when calling this method.


isFile

public boolean isFile()
Returns whether or not the name specified by this locator points to a file.


isDirectory

public boolean isDirectory()
Returns whether or not the name specified by this locator points to a directory.


isRemote

public boolean isRemote()
Returns true if the locator points to a remote file or directory.


size

public long size()
Returns the size of the file or 0 if it does not exist.


lastModified

public long lastModified()
Returns the timestamp of when the file was last modified or 0 in any case of error.


getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an opened input stream on the file defined by this locator.

Throws:
java.io.IOException

getParent

public FileLocator getParent()
Returns the parent of the file represented by this locator


isInArchive

public boolean isInArchive()
Returns whether or not the file specified by this locator is inside an archive.


getPath

public java.lang.String getPath()
Returns the full pathname.


getAbsolutePath

public java.lang.String getAbsolutePath()
Returns the full absolute pathname.


getStandardizedPath

public java.lang.String getStandardizedPath()
Returns the full pathname in a standardized for. That is all ".." and "." elements are removed and forward slashes are used as separators of the remaining elements.


getStandardizedAbsolutePath

public java.lang.String getStandardizedAbsolutePath()
Returns the full absolute pathname in a standardized form. That is all ".." and "." elements are removed and forward slashes are used as separators of the remaining elements.


exception

public java.lang.Exception exception()
Returns the last exception that occured while using this locator or null, if no exception was thrown at all.


toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Returns the name of the file as an URL.

Throws:
java.net.MalformedURLException