|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ArchiveDetector
Detects archive files solely by scanning file paths -
usually by testing for file name suffixes like .zip or the
like.
Whenever an archive file is recognized, the
getArchiveDriver(String)
method returns an instance of the
ArchiveDriver
interface which allows to access it.
ArchiveDetector
instances are assigned to File
instances in the following way:
File
class or any other method which
creates File
instances (e.g. listFiles(*)
),
then this archive detector is used.
File.getDefaultArchiveDetector()
is used.
This is initially set to the predefined instance DEFAULT
.
Both the class property and the predefined instance can be customized.
An archive file which has been recognized by an archive detector is said
to be a prospective archive file.
On the first read or write access to a prospective archive file, TrueZIP
checks its true state in cooperation with the ArchiveDriver
.
If the true state of the file turns out to be actually a directory or not
to be compatible to the archive file format, it's said to be a false
positive archive file.
TrueZIP implements the appropriate behavior for all read or write
operations according to the true state.
Thanks to this design, TrueZIP detects and handles all kinds of false
positives correctly.
Implementations must be (virtually) immutable and hence thread safe.
Rather than implementing ArchiveDetector
directly, it's easier
to instantiate or subclass the DefaultArchiveDetector
class.
This class provides a registry for archive file suffixes and archive drivers
which can be easily customized via configuration files or Java code.
Since TrueZIP 6.4, although it's not required, it's recommended for
implementations to implement the Serializable
interface,
too, so that File
instances which use it can
be serialized.
DefaultArchiveDetector
,
File
,
ArchiveDriver
Field Summary | |
---|---|
static DefaultArchiveDetector |
ALL
Recognizes all archive file suffixes registerd in the global registry by the configuration file(s). |
static DefaultArchiveDetector |
DEFAULT
Recognizes the archive file suffixes defined by the key DEFAULT in the configuration file(s). |
static DefaultArchiveDetector |
NULL
Never recognizes archive files in a path. |
Method Summary | |
---|---|
File |
createFile(File blueprint)
Constructs a new File instance from the given
blueprint . |
File |
createFile(File delegate,
File innerArchive)
This factory method is not for public use - do not use it! |
File |
createFile(File blueprint,
File delegate,
File enclArchive)
This factory method is not for public use - do not use it! |
File |
createFile(File parent,
String child)
Constructs a new File instance which uses this
ArchiveDetector to detect any archive files in its pathname. |
File |
createFile(String path)
Constructs a new File instance which uses this
ArchiveDetector to detect any archive files in its pathname. |
File |
createFile(String parent,
String child)
Constructs a new File instance which uses this
ArchiveDetector to detect any archive files in its pathname. |
File |
createFile(URI uri)
Constructs a new File instance from the given
uri . |
FileInputStream |
createFileInputStream(File file)
Creates a new FileInputStream to read the content of the
given file. |
FileOutputStream |
createFileOutputStream(File file,
boolean append)
Creates a new FileOutputStream to write the new content of the
given file. |
ArchiveDriver |
getArchiveDriver(String path)
Detects whether the given path identifies a prospective
archive file or not by applying heuristics to it and returns an
appropriate ArchiveDriver to use or null
if the path does not denote a prospective archive file or an
appropriate ArchiveDriver is not available for some
reason. |
Field Detail |
---|
static final DefaultArchiveDetector NULL
DefaultArchiveDetector
instances or if archive files
shall be treated like ordinary files rather than (virtual) directories.
DefaultArchiveDetector
static final DefaultArchiveDetector DEFAULT
DEFAULT
in the configuration file(s).
If only TrueZIP's default configuration file is used, then this is set
so that no additional JARs are required on the runtime class path.
This archive detector is initially returned by
File.getDefaultArchiveDetector()
.
Note that the actual set of archive file suffixes detected by this instance may be extended without prior notice in future releases.
How Configuration Files are located and
processed by the DefaultArchiveDetector class
static final DefaultArchiveDetector ALL
Note that the actual set of archive file suffixes detected by this instance may be extended without prior notice in future releases.
How Configuration Files are located and
processed by the DefaultArchiveDetector class
Method Detail |
---|
ArchiveDriver getArchiveDriver(String path)
path
identifies a prospective
archive file or not by applying heuristics to it and returns an
appropriate ArchiveDriver
to use or null
if the path does not denote a prospective archive file or an
appropriate ArchiveDriver
is not available for some
reason.
Please note that implementations must not check the actual
contents of the file identified by path
!
This is because this method may be used to detect archive files
by their names before they are actually created or to detect archive
files which are enclosed in other archive files, in which case there
is no way to check the file contents in the real file system.
path
- The (not necessarily absolute) path of the prospective
archive file.
This does not actually need to be accessible in the real file
system!
ArchiveDriver
instance for this archive file
or null
if the path does not denote an archive
file (i.e. the path does not have a known suffix)
or an appropriate ArchiveDriver
is not available
for some reason.
NullPointerException
- If path
is null
.
RuntimeException
- A subclass is thrown if loading or
instantiating an archive driver class fails.File createFile(File blueprint)
File
instance from the given
blueprint
.
createFile
in interface FileFactory
blueprint
- The file to use as a blueprint. If this is an instance
of the File
class, its fields are simply copied.
File
.File createFile(File delegate, File innerArchive)
createFile
in interface FileFactory
File createFile(File blueprint, File delegate, File enclArchive)
createFile
in interface FileFactory
File createFile(String path)
File
instance which uses this
ArchiveDetector
to detect any archive files in its pathname.
createFile
in interface FileFactory
path
- The pathname of the file.
File
.File createFile(String parent, String child)
File
instance which uses this
ArchiveDetector
to detect any archive files in its pathname.
createFile
in interface FileFactory
parent
- The parent pathname as a String
.child
- The child pathname as a String
.
File
.File createFile(File parent, String child)
File
instance which uses this
ArchiveDetector
to detect any archive files in its pathname.
createFile
in interface FileFactory
parent
- The parent pathname as a File
.child
- The child pathname as a String
.
File
.File createFile(URI uri)
File
instance from the given
uri
. This method behaves similar to
new java.io.File(uri)
with the following
amendment:
If the URI matches the pattern
(jar:)*file:(path!/)*entry
, then the
constructed file object treats the URI like a (possibly ZIPped) file.
The newly created File
instance uses this
ArchiveDetector
to detect any archive files in its pathname.
createFile
in interface FileFactory
uri
- an absolute, hierarchical URI with a scheme equal to
file
or jar
, a non-empty path component,
and undefined authority, query, and fragment components.
File
.
NullPointerException
- if uri
is null
.
IllegalArgumentException
- if the preconditions on the
parameter uri
do not hold.FileInputStream createFileInputStream(File file) throws FileNotFoundException
FileInputStream
to read the content of the
given file.
createFileInputStream
in interface FileFactory
file
- The file to read.
FileInputStream
.
FileNotFoundException
- On any I/O related issue when opening the file.FileOutputStream createFileOutputStream(File file, boolean append) throws FileNotFoundException
FileOutputStream
to write the new content of the
given file.
createFileOutputStream
in interface FileFactory
file
- The file to write.append
- If true
the new content should be appended
to the old content rather than overwriting it.
FileOutputStream
.
FileNotFoundException
- On any I/O related issue when opening the file.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |