Methods Summary |
---|
protected java.util.zip.ZipFile | archive()Returns the file this locator presents as opened zip file or
null in any case of error.
if ( this.getZipFile() == null )
{
this.setZipFile( new ZipFile( this.fileRef() ) ) ;
}
return this.getZipFile() ;
|
protected java.util.zip.ZipEntry | archiveEntry()
return this.entryFromArchive( this.getFile().getPath() ) ;
|
protected java.util.zip.ZipFile | container()Returns the zip file which is presented by the parent container
or null in any case of error.
if ( this.isInArchive() )
return this.getParent().archive() ;
else
return null ;
|
protected java.io.File | convertFromURLSyntax(java.io.File file)
String newStr ;
newStr = file.getPath().substring( FILE_PROTOCOL_INDICATOR.length() ) ;
newStr = str().replaceAll( newStr, ARCHIVE_INDICATOR, File.separator ) ;
return new File( newStr ) ;
|
public static org.pf.file.FileLocator | create(java.io.File file)Create a file locator that corresponds to the given file name.
FileLocator locator = new FileLocator() ;
return locator.createFrom( file ) ;
|
public static org.pf.file.FileLocator | create(java.lang.String filename)Create a file locator that corresponds to the given file name.
return create( new File( filename ) ) ;
|
protected org.pf.file.FileLocator | createFrom(java.io.File filePath)
FileLocator locator = null ;
String[] parts = null ;
File path = filePath ;
if ( path.getPath().startsWith( FILE_PROTOCOL_INDICATOR ) )
path = this.convertFromURLSyntax( path ) ;
parts = str().parts( path.getPath(), File.separator ) ;
try
{
locator = this.initFromPath( parts, path.getPath().startsWith( File.separator ) ) ;
}
catch ( Exception ex )
{
this.setException( ex ) ;
this.doesNotExist( path ) ;
locator = this ;
}
return locator ;
|
private org.pf.file.FileLocator | createFrom(org.pf.file.FileLocator aParent, java.lang.String[] pathElements)
this.setParent( aParent ) ;
return this.initFromPath( pathElements, false ) ;
|
protected boolean | doesElementExist(java.io.File element)
if ( this.isInArchive() )
{
return doesElementExistInArchive( element.getPath() ) ;
}
else
{
return element.exists() ;
}
|
protected boolean | doesElementExistInArchive(java.lang.String elementName)
ZipEntry entry ;
entry = this.entryFromArchive( elementName ) ;
return ( entry != null ) ;
|
protected void | doesNotExist(java.io.File file)
this.setExists( false ) ;
this.setFile( file ) ;
|
protected java.util.zip.ZipEntry | entryFromArchive(java.lang.String elementName)
ZipEntry entry ;
ZipFile archive ;
String name ;
name = str().replaceAll( elementName, "\\", "/" ) ;
archive = this.container() ;
entry = archive.getEntry( name ) ;
if (DEBUG)
{
// if ( entry == null ) com.mdcs.joi.Inspector.inspect( name ) ;
System.out.print( archive.getName() + "::" + name + " --- "
+ ( entry != null ) ) ;
if ( entry == null )
{
System.out.println() ;
}
else
{
System.out.print( " (" + entry.getSize() + ")" ) ;
System.out.print( " (T:" + entry.getTime() + ")" ) ;
System.out.println( " (" + ( entry.isDirectory() ? "Dir" : "File" ) + ")" ) ;
}
}
return entry ;
|
public java.lang.Exception | exception()Returns the last exception that occured while using this locator
or null, if no exception was thrown at all.
return this.getException() ;
|
public boolean | exists()Returns whether or not the file specified by this locator exists.
return this.getExists() ;
|
protected java.io.File | fileRef()
InputStream archiveStream ;
FileOutputStream fileStream ;
ZipEntry entry ;
File tempFile ;
if ( this.isInArchive() )
{
entry = this.archiveEntry() ;
archiveStream = this.container().getInputStream( entry ) ;
tempFile = File.createTempFile( "FLOC_", ".xtr" ) ;
tempFile.deleteOnExit() ;
fileStream = new FileOutputStream( tempFile ) ;
fileUtil().copyStream( archiveStream, fileStream ) ;
return tempFile ;
}
else
{
return this.getFile() ;
}
|
protected FileUtil | fileUtil()
return FileUtil.current() ;
|
protected java.io.File | fullFilePath(boolean absolute)
File full ;
if ( this.isInArchive() )
{
full = new File( this.getParent().fullFilePath( absolute ),
this.getFile().getPath() ) ;
}
else
{
if ( absolute )
full = this.getFile().getAbsoluteFile() ;
else
full = this.getFile() ;
}
return full ;
|
public java.lang.String | getAbsolutePath()Returns the full absolute pathname.
return this.fullFilePath( true ).getPath() ;
|
protected java.lang.Exception | getException()
return exception ;
|
protected boolean | getExists()
return exists ;
|
protected java.io.File | getFile()
return file ;
|
public java.io.InputStream | getInputStream()Returns an opened input stream on the file defined by this locator.
ZipEntry entry ;
if ( this.isInArchive() )
{
entry = this.archiveEntry() ;
return this.container().getInputStream( entry ) ;
}
else
{
return new FileInputStream( this.getFile() ) ;
}
|
protected org.pf.file.FileLocator | getParent()
return parent ;
|
public java.lang.String | getPath()Returns the full pathname.
return this.fullFilePath( false ).getPath() ;
|
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.
return this.fileUtil().standardize( this.getAbsolutePath() ) ;
|
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.
return this.fileUtil().standardize( this.getPath() ) ;
|
protected java.util.zip.ZipFile | getZipFile()
return zipFile ;
|
protected org.pf.file.FileLocator | initFromPath(java.lang.String[] parts, boolean startsFromRoot)
FileLocator locator = this ;
File pathElement = null ;
String[] rest = null ;
boolean elementExists = false ;
if ( startsFromRoot )
pathElement = new File( File.separator ) ;
for ( int i = 0 ; i < parts.length ; i++ )
{
if ( pathElement == null )
pathElement = new File( parts[i] ) ;
else
pathElement = new File( pathElement, parts[i] ) ;
elementExists = this.doesElementExist( pathElement ) ;
if ( elementExists )
{
this.setFile( pathElement ) ;
if ( this.isFileElement( pathElement ) )
{
if ( DEBUG ) System.out.println( "Locator(" + pathElement + ")" ) ;
if ( i < ( parts.length - 1 ) ) // Is not last element ?
{
rest = str().copyFrom( parts, i + 1 ) ;
// if (DEBUG) com.mdcs.joi.Inspector.inspect( "SubLocator", rest ) ;
locator = FileLocator.newWith( this, rest ) ;
}
break ;
}
}
else
{
if ( this.isInArchive() )
{
if ( i < ( parts.length - 1 ) ) // Is not last element ?
{
// Directories are not always identifiable individually in zip archives.
// Therefore it must be accepted that they are not found.
// So in such case no exception will be thrown.
}
else
{
throw new Exception( "\"" + pathElement.getPath() + "\" does not exist" );
}
}
else
{
throw new Exception( "\"" + pathElement.getPath() + "\" does not exist" );
}
}
}
return locator ;
|
public boolean | isDirectory()Returns whether or not the name specified by this locator
points to a directory.
try
{
if ( this.exists() )
return ! this.isFileElement( this.getFile() ) ;
else
return false ;
}
catch(Exception e)
{
return false ;
}
|
public boolean | isFile()Returns whether or not the name specified by this locator
points to a file.
try
{
if ( this.exists() )
return this.isFileElement( this.getFile() ) ;
else
return false ;
}
catch(Exception e)
{
return false ;
}
|
protected boolean | isFileElement(java.io.File element)
if ( this.isInArchive() )
{
return isFileInArchive( element.getPath() ) ;
}
else
{
return element.isFile() ;
}
|
protected boolean | isFileInArchive(java.lang.String elementName)
ZipEntry entry ;
entry = this.entryFromArchive( elementName ) ;
// Unfortunately entry.isDirectory() returns false even for
// pure directory entries inside a zip archive, so it can't be used here.
// The trick below is problematic, because apart from
// directories it will also not recognize files with size 0.
return ( entry != null ) && ( entry.getSize() > 0 ) ;
|
public boolean | isInArchive()Returns whether or not the file specified by this locator
is inside an archive.
return this.getParent() != null ;
|
public long | lastModified()Returns the timestamp of when the file was last modified
or 0 in any case of error.
ZipEntry entry ;
try
{
if ( this.isInArchive() )
{
entry = this.archiveEntry() ;
return entry.getTime() ;
}
else
{
return this.getFile().lastModified() ;
}
}
catch(Exception ex)
{
if ( DEBUG ) ex.printStackTrace() ;
return 0L ;
}
|
private static org.pf.file.FileLocator | newWith(org.pf.file.FileLocator aParent, java.lang.String[] pathElements)
FileLocator locator = new FileLocator() ;
return locator.createFrom( aParent, pathElements ) ;
|
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 none existing file, this method
returns false.
File aFile ;
try
{
aFile = this.fileRef() ;
}
catch (Exception e)
{
aFile = null ;
}
return aFile ;
|
protected void | setException(java.lang.Exception newValue) exception = newValue ;
|
protected void | setExists(boolean newValue) exists = newValue ;
|
protected void | setFile(java.io.File newValue) file = newValue ;
|
protected void | setParent(org.pf.file.FileLocator newValue) parent = newValue ;
|
protected void | setZipFile(java.util.zip.ZipFile newValue) zipFile = newValue ;
|
public long | size()Returns the size of the file or 0 if it does not exist.
ZipEntry entry ;
try
{
if ( this.isInArchive() )
{
entry = this.archiveEntry() ;
// if ( DEBUG ) com.mdcs.joi.Inspector.inspectWait( entry ) ;
return entry.getSize() ;
}
else
{
return this.getFile().length() ;
}
}
catch(Exception ex)
{
if ( DEBUG ) ex.printStackTrace() ;
return 0L ;
}
|
protected org.pf.text.StringUtil | str()
return StringUtil.current() ;
|
public java.net.URL | toURL()Returns the name of the file as an URL.
StringBuffer buffer = new StringBuffer( 128 ) ;
this.urlPath( buffer ) ;
return new URL( buffer.toString() ) ;
|
protected void | urlPath(java.lang.StringBuffer buffer)
if ( this.isInArchive() )
{
this.getParent().urlPath( buffer ) ;
buffer.append( ARCHIVE_INDICATOR ) ;
}
else
{
buffer.append( FILE_PROTOCOL_INDICATOR ) ;
}
buffer.append( this.getFile().getPath() ) ;
|