ptolemy.actor.lib.io
Class DirectoryListing
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.Source
ptolemy.actor.lib.LimitedFiringSource
ptolemy.actor.lib.SequenceSource
ptolemy.actor.lib.io.DirectoryListing
- All Implemented Interfaces:
- java.io.FilenameFilter, java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
public class DirectoryListing
- extends SequenceSource
- implements java.io.FilenameFilter
Given a URL or directory name, this actor produces an array of file names
in that directory that match an (optional) pattern. The file names that
are returned are absolute. The pattern is
a regular expression. For a reference on regular expression syntax see:
http://java.sun.com/docs/books/tutorial/extra/regex/index.html.
If directoryOrURL is a local directory (not a URL), then you can
optionally list only contained files or directories.
If listOnlyDirectories is true, then only directories will be
listed on the output. If listOnlyFiles is true, then only
files will be listed on the output. If both are true, then an exception
is thrown.
If directoryOrURL is a URL, then this actor assumes that the
server will list the contents of the referenced directory in an
HTML file where each file listed will have the following form:
<a href="filename">filename</a>
If the filename is longer than 20 characters, then only the first
20 characters of the two appearances of the filename are compared,
since some servers truncate the file names.
Note that DirectoryListing returns the contents of the directory
in a different order depending on whether one is using the Sun JVM
or the IBM JVM. Thus, you may want to connect the output to an
ArraySort actor.
- Since:
- Ptolemy II 4.0
- Version:
- $Id: DirectoryListing.java 57040 2010-01-27 20:52:32Z cxh $
- Author:
- Christopher Hylands, Edward A. Lee
- See Also:
- Serialized Form
- Accepted Rating:
- Proposed Rating:
Field Summary |
private java.util.regex.Pattern |
_pattern
|
FilePortParameter |
directoryOrURL
The directory name or URL from which to read. |
Parameter |
listOnlyDirectories
If true, and directoryOrURL refers to a local directory (not a URL),
then only directories will be listed on the output. |
Parameter |
listOnlyFiles
If true, and directoryOrURL refers to a local directory (not a URL),
then only files will be listed on the output. |
StringParameter |
pattern
If non-empty, then only output file and directory names that
match the specified (regular expression) pattern. |
Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Method Summary |
private void |
_readURL(java.net.URL sourceURL)
Read the URL and produce output. |
boolean |
accept(java.io.File directory,
java.lang.String name)
Return true if the specified name matches the specified pattern,
or if no pattern has been specified. |
void |
attributeChanged(Attribute attribute)
Override the base class to locally cache parameter values. |
void |
fire()
Output an array containing file and/or directory names. |
Methods inherited from class ptolemy.actor.AtomicActor |
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup |
Methods inherited from class ptolemy.kernel.ComponentEntity |
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName |
Methods inherited from class ptolemy.kernel.Entity |
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName |
Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
directoryOrURL
public FilePortParameter directoryOrURL
- The directory name or URL from which to read. This is a string with
any form accepted by
FilePortParameter
.
listOnlyDirectories
public Parameter listOnlyDirectories
- If true, and directoryOrURL refers to a local directory (not a URL),
then only directories will be listed on the output. If directoryOrURL
is a URL, then this parameter is ignored (there appears to be no reliable
way to tell whether the URL refers to a directory or file).
This is a boolean that defaults to false.
listOnlyFiles
public Parameter listOnlyFiles
- If true, and directoryOrURL refers to a local directory (not a URL),
then only files will be listed on the output. If directoryOrURL
is a URL, then this parameter is ignored (there appears to be no reliable
way to tell whether the URL refers to a directory or file).
This is a boolean that defaults to false.
pattern
public StringParameter pattern
- If non-empty, then only output file and directory names that
match the specified (regular expression) pattern.
The default value of this parameter is the empty String "",
which indicates that everything matches.
_pattern
private java.util.regex.Pattern _pattern
DirectoryListing
public DirectoryListing(CompositeEntity container,
java.lang.String name)
throws IllegalActionException,
NameDuplicationException
- Construct an actor with the given container and name.
- Parameters:
container
- The container.name
- The name of this actor.
- Throws:
IllegalActionException
- If the actor cannot be contained
by the proposed container.
NameDuplicationException
- If the container already has an
actor with this name.
accept
public boolean accept(java.io.File directory,
java.lang.String name)
- Return true if the specified name matches the specified pattern,
or if no pattern has been specified.
- Specified by:
accept
in interface java.io.FilenameFilter
- Parameters:
directory
- The directory in which the file was found
(ignored, but required by the FilenameFilter interface).name
- The name of the file or directory.
- Returns:
- True if the specified name matches.
attributeChanged
public void attributeChanged(Attribute attribute)
throws IllegalActionException
- Override the base class to locally cache parameter values.
- Overrides:
attributeChanged
in class LimitedFiringSource
- Parameters:
attribute
- The attribute that has changed.
- Throws:
IllegalActionException
- If the specified attribute
is URL and the file cannot be opened.
fire
public void fire()
throws IllegalActionException
- Output an array containing file and/or directory names.
- Specified by:
fire
in interface Executable
- Overrides:
fire
in class Source
- Throws:
IllegalActionException
- If there's no director or
if the directory or URL is invalid.
_readURL
private void _readURL(java.net.URL sourceURL)
throws java.io.IOException,
IllegalActionException
- Read the URL and produce output.
- Parameters:
sourceURL
- The source URL.
- Throws:
java.io.IOException
IllegalActionException