|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.meta.model.AbstractSequence<E> dk.rode.thesis.templatemethod.SequenceTemplate<ZipEntry,InputStream> dk.rode.thesis.templatemethod.ZipSequence
@Participant(value="ConcreteClass") public class ZipSequence
A zip sequence delivers input streams as sequence values, where each stream correspond to the current zip file entry.
Note, that since sequences always have a current value, a zip stream sequence cannot describe zip files with no zip entries.
Implementation notes:
A zip sequence utilises a single internal zip input stream to
deliver all sequence values until reset or restart, where it
is discarded, and a new one created and so forth. The returned
input streams are protection proxies
to ensure that the underlying stream cannot be closed or
reset.
Nested Class Summary | |
---|---|
(package private) class |
ZipSequence.ReadOnlyInputStream
A read-only input stream is a protection proxy (decorator) that ensures that a given input stream cannot be closed or reset by an external context. |
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private File |
file
The file representing the physical zip file. |
private ZipInputStream |
stream
The zip input stream used to read the zip entries from the zip archive represented by file . |
Fields inherited from class dk.rode.thesis.templatemethod.SequenceTemplate |
---|
POLICY |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
ZipSequence(File file)
Constructor. |
|
ZipSequence(File directory,
String filename)
Constructor. |
|
ZipSequence(ZipSequence sequence)
Copy constructor. |
Method Summary | |
---|---|
private void |
closeStream()
Closes the current internal zip stream used by this sequence. |
boolean |
consistent()
Returns true if this sequence is consistent, i.e. deliver the same values, in order, after restart or reset . |
ZipSequence |
copy()
Returns a copy of this sequence that will start at the same sequence index as this sequence. |
protected InputStream |
nextValue(ZipEntry key,
InputStream current)
Creates and returns a new input stream to be delivered as the sequence value. |
protected ZipEntry |
nextValueOpen(InputStream current)
Prepares this sequence for the next sequence value to
be delivered based on the current value supplied
as current . |
private void |
openStream()
Opens a new internal zip stream based on the physical zip file used by this zip sequence. |
protected void |
sequenceClose()
Performs sub-class specific procedures for closing
this sequence. |
protected boolean |
sequenceOpen(Object... arguments)
Performs sub-class specific initialisation of this sequence before sequence values will be delivered, and returns true upon success. |
protected void |
sequenceReset()
Performs sub-class specific reset of this
sequence before sequence values will be delivered. |
Methods inherited from class dk.rode.thesis.templatemethod.SequenceTemplate |
---|
bounded, close, current, ensureOpen, finalize, index, isClosed, next, nextValueClose, reset, size, unique |
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
getStringablePolicy, state, toString, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private File file
Never null.
private ZipInputStream stream
file
. Can be null.
Constructor Detail |
---|
public ZipSequence(File file) throws SequenceValueException
file
- The file representing the physical zip file; cannot be null.
NullPointerException
- If file
is null.
SequenceValueException
- If file
does not exist, or if it
represents a directory, or if the initialisation fails otherwise.public ZipSequence(File directory, String filename) throws SequenceValueException
directory
- The directory where the zip file is to be found; can be
null, i.e. "current" directory.filename
- The zip file name; cannot be null.
NullPointerException
- If name
is null.
SequenceValueException
- If a zip file with name
does not exist
in directory
, or if it represents a directory, or if the
initialisation fails otherwise.public ZipSequence(ZipSequence sequence) throws SequenceValueException
If sequence
is closed
, this
sequence will be closed as well.
sequence
- The sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.
SequenceValueException
- If the initialisation fails, or if the
current value of this sequence cannot be fetched.Method Detail |
---|
private final void closeStream() throws IOException
IOException
- If the zip entry corresponding to the current
value cannot be closed, or if the zip stream cannot be
closed.public boolean consistent()
Sequence
reset
.
Only bounded
consistent sequences will restart.
Consistent sequences need not deliver unique
sequence values.
Instances of the same type of sequences are always consistent or inconsistent; it is determined at design time, not construction time.
consistent
in interface Sequence<InputStream>
consistent
in class SequenceTemplate<ZipEntry,InputStream>
public ZipSequence copy()
Sequence
protected InputStream nextValue(ZipEntry key, InputStream current)
nextValue
in class SequenceTemplate<ZipEntry,InputStream>
key
- The correlation key just created by
nextValueOpen(E)
; can be null.current
- The current (soon to be previous) sequence value; never null
unless initialising this sequence (once).
SequenceTemplate.next()
returns; null means sequence restart,
which is only allowed if this sequence is bounded
.protected ZipEntry nextValueOpen(InputStream current) throws Exception
SequenceTemplate
next
sequence value to
be delivered based on the current
value supplied
as current
. This is step 1/3 in value creation, where
the next steps are nextValue(K, E)
and
nextValueClose(K, E)
.
The returned correlation key will be used to identify the
same creation process in subsequent calls to nextValue
and nextValueClose
.
nextValueOpen
in class SequenceTemplate<ZipEntry,InputStream>
current
- The current (soon to be previous) sequence value; never null
unless initialising this sequence (once).
ZipEntry
in the zip stream; can be null in
case the stream has no more entries (restart).
Exception
- If the zip stream entry represented by
current
cannot be closed, or if the next
zip entry cannot be fetched.private final void openStream() throws IOException
FileNotFoundException
- If the file supplied at construction
time does not exist, or if it represents a directory.
IOException
- If the stream cannot be opened otherwise.protected void sequenceClose() throws Exception
SequenceTemplate
closing
this sequence. Once this sequence is closed, sequence values can
no longer be delivered. Default implementation does nothing.
sequenceClose
in class SequenceTemplate<ZipEntry,InputStream>
Exception
- If the super sequence close method throws an
exception.SequenceTemplate.sequenceReset()
,
SequenceTemplate.sequenceOpen(Object...)
protected boolean sequenceOpen(Object... arguments) throws Exception
SequenceTemplate
closed
.
Initialisation is performed upon construction
of new sequences and when
copying
existing
sequences, if needed. The arguments supplied to this (abstract) operation
is the varargs arguments supplied at construction time (e.g. via sub-class
implementations).
sequenceOpen
in class SequenceTemplate<ZipEntry,InputStream>
arguments
- Arguments required by the initialisation, if any;
never null, but can be empty.
NullPointerException
- If no file is supplied at construction time.
Exception
- If the file supplied at construction time does not exist; if it
represents a directory; or if the stream cannot be opened otherwise.SequenceTemplate.sequenceReset()
,
SequenceTemplate.sequenceClose()
protected void sequenceReset() throws Exception
SequenceTemplate
reset
of this
sequence before sequence values will be delivered. Default implementation does nothing.
sequenceReset
in class SequenceTemplate<ZipEntry,InputStream>
Exception
- Not thrown by the default implementation.SequenceTemplate.sequenceOpen(Object...)
,
SequenceTemplate.sequenceClose()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |