public class FileLocator extends java.lang.Object implements IReleasable
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TEMP_FILE_PREFIX |
static java.lang.String |
TEMP_FILE_SUFFIX |
Modifier and Type | Method and Description |
---|---|
protected java.util.zip.ZipFile |
archive()
Returns the file this locator presents as opened zip file or
null in any case of error.
|
protected java.util.zip.ZipEntry |
archiveEntry() |
protected java.lang.String |
asRootPart(java.lang.String part) |
protected void |
closeZipFile() |
protected java.util.zip.ZipFile |
container()
Returns the zip file which is presented by the parent container
or null in any case of error.
|
protected java.io.File |
convertFromURLSyntax(java.io.File aFile) |
protected void |
copyFromRemote()
This method must only be called if the original filename contains a
URL starting with one of the supported remote protocols!
|
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.
|
static FileLocator |
createExtractedFile(FileLocator parent,
java.lang.String zipEntryName,
java.io.File extractedFile)
Create a file locator that represents an already extracted file
from inside an archive.
|
protected FileLocator |
createFrom(java.io.File filePath) |
protected FileLocator |
createFrom(FileLocator aParent,
java.lang.String[] pathElements) |
protected boolean |
doesElementExist(java.io.File element) |
protected boolean |
doesElementExistInArchive(java.lang.String elementName) |
protected void |
doesNotExist(java.io.File aFile) |
protected java.util.zip.ZipEntry |
entryFromArchive(java.lang.String elementName) |
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.
|
protected java.io.File |
fileRef()
This either returns the underlying file from the local file system or
unzipps the file from the underlying archive into a temporary file and returns
|
protected static FileUtil |
fileUtil() |
protected java.io.File |
fullFilePath(boolean absolute) |
java.lang.String |
getAbsolutePath()
Returns the full absolute pathname.
|
protected java.lang.Exception |
getException() |
protected java.lang.Boolean |
getExists() |
protected java.io.File |
getFile() |
java.io.InputStream |
getInputStream()
Returns an opened input stream on the file defined by this locator.
|
protected java.lang.String |
getNormalizedFilePath() |
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
|
protected FileLocator |
getParentLocator() |
java.lang.String |
getPath()
Returns the full pathname.
|
protected boolean |
getRemote() |
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.
|
protected java.io.File |
getTempFile() |
protected java.io.File |
getUnderlyingRealFile()
This either returns the underlying file from the local file system or
unzipps the file from the underlying archive into a temporary file and returns
In any case of error null wil be returned.
|
protected java.util.zip.ZipFile |
getZipFile() |
protected void |
handleException(java.lang.Exception ex) |
protected FileLocator |
initFromPath(java.lang.String[] parts,
boolean startsFromRoot) |
boolean |
isDirectory()
Returns whether or not the name specified by this locator
points to a directory.
|
protected boolean |
isDirectoryElement(java.io.File element) |
protected boolean |
isDirectoryInArchive(java.lang.String elementName) |
boolean |
isFile()
Returns whether or not the name specified by this locator
points to a file.
|
protected boolean |
isFileElement(java.io.File element) |
protected boolean |
isFileInArchive(java.lang.String elementName) |
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.
|
protected boolean |
isResolved() |
boolean |
isTempFile()
Returns true if the underlying file has been resolved and copied
to a temporary file in the local file system.
|
protected boolean |
isUnlocatedRemoteFile() |
long |
lastModified()
Returns the timestamp of when the file was last modified
or 0 in any case of error.
|
protected Logger |
logger() |
java.io.File |
realFile()
Returns the file that contains the data the locator points to.
|
void |
release()
Releases any allocated objects (e.g.
|
protected boolean |
resolveIfNecessary()
Checks if the referred file has already been resolved.
|
protected void |
setException(java.lang.Exception newValue) |
protected void |
setExists(java.lang.Boolean newValue) |
protected void |
setFile(java.io.File newValue) |
protected void |
setIsResolved(boolean resolved) |
protected void |
setOriginalFileName(java.lang.String newValue) |
protected void |
setParentLocator(FileLocator newValue) |
protected void |
setRemote(boolean newValue) |
protected void |
setResolvedAsTempFile(java.io.File temporaryFile) |
protected void |
setTempFile(java.io.File aFile) |
protected void |
setZipFile(java.util.zip.ZipFile newValue) |
long |
size()
Returns the size of the file or 0 if it does not exist.
|
protected static StringUtil |
str() |
java.lang.String |
toString() |
java.net.URL |
toURL()
Returns the name of the file as an URL.
|
protected void |
urlPath(java.lang.StringBuffer buffer) |
protected static boolean |
usesSupportedRemoteProtocol(java.lang.String filename) |
public static final java.lang.String TEMP_FILE_PREFIX
public static final java.lang.String TEMP_FILE_SUFFIX
public static FileLocator create(java.io.File file)
public static FileLocator create(java.net.URL url)
url
- The url that specifies the filepublic static FileLocator create(java.lang.String filename)
filename
- The name (or URL) that specifies the filepublic static FileLocator createExtractedFile(FileLocator parent, java.lang.String zipEntryName, java.io.File extractedFile)
parent
- The file locator that represents the parent archive (must not be null).zipEntryName
- The full name of the entry in the zip archive (must not be null.extractedFile
- The file that has been extracted from the parent archive (must not be null).protected static boolean usesSupportedRemoteProtocol(java.lang.String filename)
protected static StringUtil str()
protected static FileUtil fileUtil()
public java.io.File realFile()
protected boolean resolveIfNecessary()
public boolean exists()
public boolean isFile()
public boolean isDirectory()
public boolean isRemote()
public boolean isTempFile()
public long size()
public long lastModified()
public java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
public FileLocator getParent()
public boolean isInArchive()
public java.lang.String getPath()
public java.lang.String getAbsolutePath()
public java.lang.String getStandardizedPath()
public java.lang.String getStandardizedAbsolutePath()
public java.lang.Exception exception()
public java.net.URL toURL() throws java.net.MalformedURLException
java.net.MalformedURLException
public java.lang.String toString()
toString
in class java.lang.Object
public void release()
release
in interface IReleasable
public java.lang.String getOriginalFileName()
protected FileLocator createFrom(java.io.File filePath)
protected FileLocator createFrom(FileLocator aParent, java.lang.String[] pathElements) throws java.lang.Exception
java.lang.Exception
protected FileLocator initFromPath(java.lang.String[] parts, boolean startsFromRoot) throws java.lang.Exception
java.lang.Exception
protected boolean doesElementExist(java.io.File element) throws java.lang.Exception
java.lang.Exception
protected boolean isFileElement(java.io.File element) throws java.lang.Exception
java.lang.Exception
protected boolean isDirectoryElement(java.io.File element) throws java.lang.Exception
java.lang.Exception
protected boolean doesElementExistInArchive(java.lang.String elementName) throws java.lang.Exception
java.lang.Exception
protected boolean isFileInArchive(java.lang.String elementName) throws java.lang.Exception
java.lang.Exception
protected boolean isDirectoryInArchive(java.lang.String elementName)
protected java.util.zip.ZipEntry entryFromArchive(java.lang.String elementName) throws java.io.IOException
java.io.IOException
protected java.util.zip.ZipEntry archiveEntry() throws java.io.IOException
java.io.IOException
protected void doesNotExist(java.io.File aFile)
protected java.io.File fullFilePath(boolean absolute)
protected void urlPath(java.lang.StringBuffer buffer)
protected java.io.File getUnderlyingRealFile()
protected java.io.File fileRef() throws java.io.IOException
java.io.IOException
protected java.util.zip.ZipFile archive() throws java.io.IOException
java.io.IOException
protected java.util.zip.ZipFile container() throws java.io.IOException
java.io.IOException
protected void closeZipFile()
protected java.io.File convertFromURLSyntax(java.io.File aFile)
protected java.lang.String getNormalizedFilePath()
protected boolean isUnlocatedRemoteFile()
protected void copyFromRemote()
protected void setResolvedAsTempFile(java.io.File temporaryFile)
protected java.lang.String asRootPart(java.lang.String part)
protected void setOriginalFileName(java.lang.String newValue)
protected FileLocator getParentLocator()
protected void setParentLocator(FileLocator newValue)
protected java.io.File getFile()
protected void setFile(java.io.File newValue)
protected java.util.zip.ZipFile getZipFile()
protected void setZipFile(java.util.zip.ZipFile newValue)
protected java.lang.Boolean getExists()
protected void setExists(java.lang.Boolean newValue)
protected java.lang.Exception getException()
protected void setException(java.lang.Exception newValue)
protected boolean getRemote()
protected void setRemote(boolean newValue)
protected java.io.File getTempFile()
protected void setTempFile(java.io.File aFile)
protected boolean isResolved()
protected void setIsResolved(boolean resolved)
protected void handleException(java.lang.Exception ex)
protected Logger logger()