Class FileArchive
- All Implemented Interfaces:
AutoCloseable,org.glassfish.api.deployment.archive.Archive,org.glassfish.api.deployment.archive.ReadableArchive,org.glassfish.api.deployment.archive.WritableArchive
If the directory underlying the FileArchive is created by GlassFish then FileArchive filters its contents so only those files more recent than the creation of the archive itself are visible to consumers.
The main motivation is to hide unwanted "left-over" files from previous deployments that might linger, especially on Windows, after the previous app had been undeployed. (Deployment uses a FileArchive to extract the user's JAR-based archive into the applications directory.) Historically such left-over files arise after GlassFish expands an archive into its exploded form but then some code opens but does not close a file in that exploded directory tree.
An open left-over file can be overwritten-in-place on Windows, and this happens when a caller invokes
putNextEntry(java.lang.String) to create a new entry (file) inside the archive. But a left-over file that
is not in the new app but is still open by GlassFish cannot be deleted or renamed on Windows and so it will remain in
the expansion directory. Such left-over files, if not filtered out, can confuse GlassFish and the application. By
"stamping" the archive creation date we can filter out such old, left-over files.
To support this feature, when FileArchive creates a directory it stores a marker file there, the contents of which records the creation date/time of the archive. We cannot just use the lastModified value for the top-level directory. Users might legitimately use "touch .reload" in the applications/appName directory to trigger a dynamic reload of the app. If .reload does not already exist then touch creates it, and this would update the lastModified of the directory file.
- Author:
- Jerome Dochez, Tim Quinn
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAPI which FileArchive methods should use for dealing with the StaleFileManager implementation. -
Field Summary
Fields inherited from class com.sun.enterprise.deploy.shared.AbstractReadableArchive
archiveMetaData, extraData, parentArchive -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()close the abstract archivevoidcreates a new abstract archive with the given pathorg.glassfish.api.deployment.archive.WritableArchivecreateSubArchive(String name) create or obtain an embedded archive within this abstraction.booleandelete()delete the archivebooleandeleteEntry(String name) delete an entry in the archiveentries()Returns an enumeration of the module file entries with the specified prefix.booleanexists()booleanReturns the existence of the given entry name The file name must be relative to the root of the module.longGet the size of the archiveReturns the enumeration of first level directories in this archivelonggetEntrySize(String name) Returns the entry size for a given entry name or 0 if not knowngetName()Returns the name portion of the archive's URI.org.glassfish.api.deployment.archive.ReadableArchivegetSubArchive(String name) create or obtain an embedded archive within this abstraction.getURI()Returns the URI used to create or open the underlyong archivebooleanisDirectory(String name) voidvoidOpen an abstract archiveorg.glassfish.api.deployment.archive.WritableArchiveEntryputNextEntry(String name) booleanrename the archivebooleanMethods inherited from class com.sun.enterprise.deploy.shared.AbstractReadableArchive
addArchiveMetaData, getArchiveMetaData, getExtraData, getParentArchive, removeArchiveMetaData, removeExtraData, setExtraData, setParentArchive, toString
-
Constructor Details
-
FileArchive
public FileArchive() -
FileArchive
- Throws:
IOException
-
-
Method Details
-
open
Open an abstract archive- Specified by:
openin interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Parameters:
uri- path to the archive- Throws:
IOException
-
open
- Parameters:
uri- a string representing URI- Throws:
IOException- See Also:
-
getArchiveSize
Get the size of the archive- Specified by:
getArchiveSizein interfaceorg.glassfish.api.deployment.archive.Archive- Returns:
- tje the size of this archive or -1 on error
- Throws:
NullPointerExceptionSecurityException
-
create
creates a new abstract archive with the given path- Specified by:
createin interfaceorg.glassfish.api.deployment.archive.WritableArchive- Parameters:
uri- path to create the archive- Throws:
IOException
-
close
close the abstract archive- Specified by:
closein interfaceorg.glassfish.api.deployment.archive.Archive- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
delete
public boolean delete()delete the archive- Specified by:
deletein interfaceorg.glassfish.api.deployment.archive.ReadableArchive
-
isDirectory
- Specified by:
isDirectoryin interfaceorg.glassfish.api.deployment.archive.Archive
-
entries
- Specified by:
entriesin interfaceorg.glassfish.api.deployment.archive.Archive- Returns:
- an @see java.util.Enumeration of entries in this abstract archive
-
getDirectories
Returns the enumeration of first level directories in this archive- Specified by:
getDirectoriesin interfaceorg.glassfish.api.deployment.archive.Archive- Returns:
- enumeration of directories under the root of this archive
- Throws:
IOException
-
entries
Returns an enumeration of the module file entries with the specified prefix. All elements in the enumeration are of type String. Each String represents a file name relative to the root of the module.- Specified by:
entriesin interfaceorg.glassfish.api.deployment.archive.Archive- Parameters:
prefix- the prefix of entries to be included- Returns:
- an enumeration of the archive file entries.
-
exists
public boolean exists()- Specified by:
existsin interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Returns:
- true if this archive exists
-
getSubArchive
public org.glassfish.api.deployment.archive.ReadableArchive getSubArchive(String name) throws IOException create or obtain an embedded archive within this abstraction.- Specified by:
getSubArchivein interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Parameters:
name- name of the embedded archive.- Throws:
IOException
-
createSubArchive
public org.glassfish.api.deployment.archive.WritableArchive createSubArchive(String name) throws IOException create or obtain an embedded archive within this abstraction.- Specified by:
createSubArchivein interfaceorg.glassfish.api.deployment.archive.WritableArchive- Parameters:
name- name of the embedded archive.- Throws:
IOException
-
exists
Returns the existence of the given entry name The file name must be relative to the root of the module.- Specified by:
existsin interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Parameters:
name- the file name relative to the root of the module.- Returns:
- the existence the given entry name.
- Throws:
IOException
-
getEntry
- Specified by:
getEntryin interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Parameters:
name- the entry name- Returns:
- a @see java.io.InputStream for an existing entry in the current abstract archive
- Throws:
IOException
-
getEntrySize
Returns the entry size for a given entry name or 0 if not known- Specified by:
getEntrySizein interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Parameters:
name- the entry name- Returns:
- the entry size
-
getManifest
- Specified by:
getManifestin interfaceorg.glassfish.api.deployment.archive.Archive- Returns:
- the manifest information for this abstract archive
- Throws:
IOException
-
getURI
Returns the URI used to create or open the underlyong archive- Specified by:
getURIin interfaceorg.glassfish.api.deployment.archive.Archive- Returns:
- the URI for this archive.
-
renameTo
rename the archive- Specified by:
renameToin interfaceorg.glassfish.api.deployment.archive.ReadableArchive- Parameters:
name- the archive name
-
putNextEntry
public org.glassfish.api.deployment.archive.WritableArchiveEntry putNextEntry(String name) throws IOException - Specified by:
putNextEntryin interfaceorg.glassfish.api.deployment.archive.WritableArchive- Throws:
IOException
-
getName
Returns the name portion of the archive's URI.For FileArhive the name is all of the path that follows the last slash (ignoring a slash at the end of the path).
Here are some example archive names for the specified FileArchive paths:
- /a/b/c/d/ -> d
- /a/b/c/d -> d
- /a/b/c.jar -> c.jar
- Specified by:
getNamein interfaceorg.glassfish.api.deployment.archive.Archive- Returns:
- the name of the archive
-
supportsElementsOverwriting
public boolean supportsElementsOverwriting()- Returns:
- true if this archive abstraction supports overwriting of elements
-
deleteEntry
delete an entry in the archive- Parameters:
name- the entry name- Returns:
- true if the entry was successfully deleted
-