org.pf.file
Class ClasspathElement

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

public class ClasspathElement
extends java.lang.Object

Represents one entry in a classpath. It can be asked if it s a directory or an archive. It also can be asked if it exists and it is valid (really a zip archive).

Version:
1.6.1
Author:
Manfred Duchrow

Constructor Summary
ClasspathElement(java.io.File aFile)
          Initialize the new instance with a file representing either a directory or an archive file.
ClasspathElement(java.lang.String elementName)
          Initialize the new instance with default values.
 
Method Summary
 void close()
          Close any underlying (maybe) opened archive
 boolean contains(java.lang.String filename)
          Returns whether or not this element contains a file with the given name.
 java.net.URL createURL(java.lang.String filename)
          Creates a URL for the file with the given name that is in this file container.
 boolean equals(java.lang.Object object)
          Returns true if the given object is equal to this object
 boolean exists()
          Returns whether or not this classpath element exists.
 FileInfo getFileInfo(java.lang.String filename)
          Returns a file info object for the given filename which is expected to be inside the directory or archive represented by this classpath element.
 java.lang.String getName()
          Returns the name of this classpath element
 java.net.URL getURL()
          Returns a URL that points to this classpath element.
 int hashCode()
          Returns the hash value of this object
 boolean isArchive()
          Returns true, if this element is an archive file.
 boolean isDirectory()
          Returns true, if this element is a directory
 boolean isFile()
          Returns true, if this element is a file.
 boolean isOpen()
          Returns true, if this element represents an archive (zip file) and that archive is currently open.
 boolean isValid()
          Returns true, if this element is either a valid directory or really an archive (zip file).
 boolean leaveArchiveOpen()
          Returns true, if an opened archive stays open until method close() gets called.
 void leaveArchiveOpen(boolean newValue)
          Sets whether an opened archive stays open until method close() gets called.
 java.io.InputStream open(java.lang.String filename)
          Opens the file with the given name in this classpath element and returns the input stream.
 java.lang.String toString()
          Returns the element's string representation.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClasspathElement

public ClasspathElement(java.io.File aFile)
Initialize the new instance with a file representing either a directory or an archive file.

Parameters:
aFile - A file representing an element in a classpath

ClasspathElement

public ClasspathElement(java.lang.String elementName)
Initialize the new instance with default values.

Method Detail

getName

public java.lang.String getName()
Returns the name of this classpath element


leaveArchiveOpen

public boolean leaveArchiveOpen()
Returns true, if an opened archive stays open until method close() gets called. Returns true if the archive gets closed after each access. The default is false.

See Also:
close()

leaveArchiveOpen

public void leaveArchiveOpen(boolean newValue)
Sets whether an opened archive stays open until method close() gets called. If set to false the archive gets closed after each access.

See Also:
close()

exists

public boolean exists()
Returns whether or not this classpath element exists.


isFile

public boolean isFile()
Returns true, if this element is a file. Actually it only determines, if this element is a file. This doesn't ensure that it is really an archive file.


isArchive

public boolean isArchive()
Returns true, if this element is an archive file.


isDirectory

public boolean isDirectory()
Returns true, if this element is a directory


isValid

public boolean isValid()
Returns true, if this element is either a valid directory or really an archive (zip file).


isOpen

public boolean isOpen()
Returns true, if this element represents an archive (zip file) and that archive is currently open. If it represents a directory this method returns false


contains

public boolean contains(java.lang.String filename)
Returns whether or not this element contains a file with the given name.

Parameters:
filename - The name of the file to be looked for

getFileInfo

public FileInfo getFileInfo(java.lang.String filename)
Returns a file info object for the given filename which is expected to be inside the directory or archive represented by this classpath element.

Parameters:
filename - The name of the file to be looked for
Returns:
A file info object or null if the specified file does not exist

open

public java.io.InputStream open(java.lang.String filename)
                         throws java.io.IOException
Opens the file with the given name in this classpath element and returns the input stream. If the file doesn't exist or this classpath element is not valid, null will be returned.

Parameters:
filename - The name of the file in this container to be opened
Throws:
java.io.IOException

close

public void close()
Close any underlying (maybe) opened archive


getURL

public java.net.URL getURL()
Returns a URL that points to this classpath element.


createURL

public java.net.URL createURL(java.lang.String filename)
Creates a URL for the file with the given name that is in this file container. It is not checked, if the file really exists. If this classpath element is invalid null will be returned.


toString

public java.lang.String toString()
Returns the element's string representation. The string always contains slashes, never backslashes.

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns the hash value of this object

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object object)
Returns true if the given object is equal to this object

Overrides:
equals in class java.lang.Object