|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.io.File
public class File
A class representing a File on the host file system. This class is designed for applications and may not work with applets because of security issues.
Creating a File Component
| Field Summary | |
|---|---|
protected OrderedCollection |
children
|
protected static com.sas.visuals.IconInterface |
DRIVE_ICON
|
protected static com.sas.visuals.IconInterface |
FILE_ICON
|
protected static com.sas.visuals.IconInterface |
FOLDER_ICON
|
protected static com.sas.visuals.IconInterface |
FOLDER_OPEN_ICON
|
protected boolean |
need_refresh
|
protected java.lang.String |
nodeExpandedText
full path of this file |
protected java.lang.String |
nodeText
Name of this file object |
protected java.lang.String |
nodeType
Type of file object, file or directory |
static java.lang.String |
RB_KEY
|
| Constructor Summary | |
|---|---|
File()
Default constructor for design time. |
|
File(File directory,
java.lang.String name)
Creates a new File object given a file object and the name of the File. |
|
File(FileSystem fs,
File dir,
java.lang.String name)
Creates a File on the specified file system such as UNIX or Windows and specified directory. |
|
File(java.lang.String path)
Creates a new File object. |
|
File(java.lang.String path,
java.lang.String file)
Creates a new File object. |
|
| Method Summary | |
|---|---|
protected void |
_setNodeType()
Sets the type of the File object to Directory or File. |
void |
addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Add a listener for the com.sas.collection.ContentsChangedEvent event. |
void |
apply(com.sas.util.ApplyInterface action)
Applies the 'apply' function in the action to every item in the collection. |
boolean |
chmod(int flag)
Method to change the read write permission of a file or directory, so can implement force option for delete. |
java.lang.Object |
clone()
Create a copy of the current model |
boolean |
contains(java.lang.Object element)
Test for the presence of an object in the collection |
boolean |
copyTo(File dir)
Copies the entire Directory and its contents to the specified Directory. |
boolean |
copyTo(java.lang.String path)
Copies the entire directory and its contents to the name specified in path. |
int |
count()
Gets the number of items in the Directory. |
int |
countNodeChildren(int maximumChildCount)
Counts the children of the current node. |
boolean |
delete(java.lang.String flag)
Deletes the current directory or file. |
static boolean |
delete(java.lang.String path,
java.lang.String flag)
Deletes a File specified by the path. |
boolean |
equals(StaticOrderedCollectionInterface orderedCollection)
Compare the current items with those in another collection and tell whether the collections are identical. |
void |
fireContentsChanged(com.sas.collection.ContentsChangedEvent event)
Send a ContentsChangedEvent event to all the ChangedListener objects in the listener list. |
java.lang.Object |
get(int index)
Fetch an item at a index. |
com.sas.visuals.IconInterface |
getDefaultIcon()
Returns the default icon for the current node. |
com.sas.visuals.IconInterface |
getExpandedIcon()
Returns the expanded icon for the current node. |
com.sas.visuals.IconInterface |
getExpandedSelectedIcon()
Sets the expandedSelected icon for the current node. |
static com.sas.beans.ExtendedBeanInfo |
getExtendedBeanInfo()
|
int |
getIndex(java.lang.Object element,
int startIndex)
Returns the index asschildreniated with the item (searches forward) |
java.util.Enumeration |
getItems()
Returns enumeration of File objects from a list. |
java.util.Enumeration |
getItems(int start,
int end)
Returns an enumeration of a subset of the items from a collection. |
int |
getLastIndex(java.lang.Object element,
int startIndex)
Returns the index associated with the item (searches backward) |
SimpleNodeInterface |
getNodeChild(int index)
Returns the child node at the specified index. |
int |
getNodeChildCount()
Returns the number of files and directories. |
SimpleNodeInterface[] |
getNodeChildren(int startIndex,
int count)
Returns the children of the current node in the specified range. |
java.lang.String |
getNodeExpandedText()
If the expanded text is not set then gets an absolute path name of this object. |
java.lang.String |
getNodeText()
Gets the Name of this File object. |
java.lang.String |
getNodeType()
Gets a String indicating whether this File object is a File or Directory. |
File |
getParentDir()
Gets the Parent File object for this File. |
com.sas.visuals.IconInterface |
getSelectedIcon()
Returns the selected icon for the current node. |
protected void |
initializeChildren()
|
boolean |
isLeafNode()
Returns true if this object does not have children and thus is not expandable. |
boolean |
mkdir(java.lang.String subdirectoryName)
Creates a subdirectory of this directory object. |
boolean |
mkdirs(java.lang.String subdirectoryPath)
Creates all the subdirectories listed in the path. returns false if the directories exists. |
boolean |
moveTo(java.io.File parentdir)
Moves the entire directory and its contents to the new parent directory. |
boolean |
moveTo(java.lang.String parentpath)
Moves the entire directory and its contents to the parent name specified by path. |
void |
removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
Remove a listener for the com.sas.collection.ContentsChangedEvent event. |
boolean |
renameTo(java.lang.String newName)
/** Changes the name of the File specified by the newName. |
void |
setDefaultValues()
Sets the default values |
void |
setHasChildren(boolean hasChildren)
Sets the leaf node property to the valuse passed in. |
protected void |
setNodeText(java.lang.String name)
Sets the Text of this File object to the absolute path. |
void |
sort(com.sas.util.Comparator comparator)
Sorts the items from the current collection using the provided comparison function. |
void |
sort(com.sas.util.Comparator comparator,
int start,
int end)
Sorts a range of items from the current collection using the provided comparison function. |
void |
supressChildren(boolean hasChildren)
Sets the leaf node property to the valuse passed in. |
| Methods inherited from interface com.sas.beans.PropertyChangeSource |
|---|
addPropertyChangeListener, removePropertyChangeListener |
| Field Detail |
|---|
protected OrderedCollection children
protected java.lang.String nodeText
protected java.lang.String nodeType
protected java.lang.String nodeExpandedText
protected transient boolean need_refresh
protected static com.sas.visuals.IconInterface FOLDER_ICON
protected static com.sas.visuals.IconInterface FILE_ICON
protected static com.sas.visuals.IconInterface DRIVE_ICON
protected static com.sas.visuals.IconInterface FOLDER_OPEN_ICON
public static final java.lang.String RB_KEY
| Constructor Detail |
|---|
public File()
public File(File directory,
java.lang.String name)
directory - parent Filename - name of the file
public File(FileSystem fs,
File dir,
java.lang.String name)
FileSystem - objectdir - parent File,name - of the Filepublic File(java.lang.String path)
path - absolute path. System dependent File separator
character is used in path specification.
public File(java.lang.String path,
java.lang.String file)
path - absolute path. System dependent File separator
character is used in path specification.file - name of the file| Method Detail |
|---|
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
public void setDefaultValues()
setDefaultValues in interface ComponentInterfacesetDefaultValues in class FileComponentComponentInterface.setDefaultValues()
public static boolean delete(java.lang.String path,
java.lang.String flag)
path - a string specifying the absolute path.flag - a string specifying the options recursive or force or both
public void addContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
addContentsChangedListener in interface com.sas.collection.ContentsChangedSourcelistener - an object which handles ChangedEvent events
the listener is not added a second time if it already exists
in the list of listeners for this event.ContentsChangedSourcepublic void removeContentsChangedListener(com.sas.collection.ContentsChangedListener listener)
removeContentsChangedListener in interface com.sas.collection.ContentsChangedSourcelistener - an object which handles ContentsChangedEvent eventsContentsChangedSource
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in interface StaticCollectionInterfaceclone in interface StaticOrderedCollectionInterfaceclone in interface com.sas.PublicClonableclone in class FileComponentjava.lang.CloneNotSupportedException - if the model attached to the component being cloned
will not allow the clone to attach.public void fireContentsChanged(com.sas.collection.ContentsChangedEvent event)
event - the event to sendpublic boolean copyTo(File dir)
a = d:\apps\af b = d:\backup d:\apps\af\f1 d:\backup\f1 d:\apps\af\d\s1 d:\backup\d\s1 d:\apps\af\d\s2 d:\backup\d\s2 d:\apps\af\d d:\backup\dIf the physical dir does not exist then creates a new directory and copy it.
dir - the new parent directory.
public boolean copyTo(java.lang.String path)
path - the path of the directory.
public int count()
count in interface com.sas.util.Countablepublic boolean delete(java.lang.String flag)
flag - specifying whether to delete the directory recursively and force
the delete or not. If the current File is not a direcotry but a file then will
ignore the recursive flag and delete the file.
public boolean chmod(int flag)
1 - - READ , 2 - WRITE, 3 - READ | WRITE
public SimpleNodeInterface[] getNodeChildren(int startIndex,
int count)
getNodeChildren in interface SimpleNodeInterfacestartIndex - index which identifies the start of the rangecount - number of children to return
true.public SimpleNodeInterface getNodeChild(int index)
getNodeChild in interface SimpleNodeInterfaceindex - the index of the child node to retrieve
true.public int getNodeChildCount()
getNodeChildCount in interface SimpleNodeInterfacepublic int countNodeChildren(int maximumChildCount)
countNodeChildren in interface SimpleNodeInterfacemaximumChildCount - the maximum number of children to read, or 0 to read indefinitely
public java.lang.String getNodeExpandedText()
getNodeExpandedText in interface NodeInterfacepublic boolean isLeafNode()
isLeafNode in interface SimpleNodeInterfacepublic java.lang.String getNodeText()
getNodeText in interface NodeInterfacepublic java.lang.String getNodeType()
getNodeType in interface NodeInterfacepublic java.util.Enumeration getItems()
getItems in interface com.sas.util.Enumerableprotected void initializeChildren()
public File getParentDir()
public boolean mkdir(java.lang.String subdirectoryName)
throws java.io.FileNotFoundException
eg. File f = new File("d:\\app");
boolean rc = f.exists();
boolean didMake = f.mkdir("test1");
- Will create a directory "d:\\app\\test1" only if rc == true otherwise
throws FileNotFoundException.
- If invalid argument(absolutePath or invalid separator character)
specified then didMake is false
didMake = f.mkdir();
- This is inherited method which will create a directory only if
rc == false and didMake = true
subdirectoryName - name of the subdirectory
java.io.FileNotFoundException - if this(parent)
directory does not exists.
public boolean mkdirs(java.lang.String subdirectoryPath)
throws java.io.FileNotFoundException
eg. File f = new File("d:\\app\\backup");
boolean rc = f.exists();
boolean didMake = f.mkdirs("a\\b\\c");
- Will create all the directories "d:\\app\\backup\\a\\b\\c" only if rc == true
otherwise throws FileNotFoundException.
- If invalid argument(absolutePath or invalid separator character)
specified then didMake is false
didMake = f.mkdirs();
- This is inherited method which will create all directories only if
rc == false and returns didMake = true
subdirectorypath - path of the subdirectory.
java.io.FileNotFoundException - if this(parent)
directory does not exists.public boolean moveTo(java.io.File parentdir)
eg. File newf = new File("c:\\test\\backup");
File f = new File("c:\\f1");
boolean rc = f.moveTo(newf);
- will move the file f1 from its parent directory c:\\ to
c:\\test\\backup
- will return false if the new parent is not a directory or do not
have access to the file or directory.
- if f1 is a directory will move the entire directory and its contents.
This is similar to copyTo(dir), except that if this object is a directory
then copyTo will remove that directory and copy the contents to
the new directory. Whereas moveTo will append new to the parent directory.
parentdir - the new parent directory.
public boolean moveTo(java.lang.String parentpath)
path - the directory.
public boolean renameTo(java.lang.String newName)
File f = new File("d:\\apps\\a");
if absolute path specified as an argument then
f.renameTo("d:\\test"); // will rename "d:\\apps\\a" to "d:\\test"
if only name is specified then
f.renameTo("test"); // will rename "d:\\apps\\a" to "d:\\apps\\test"
newName - path of new File. If not absolute will change the name of
the file.
protected void _setNodeType()
protected void setNodeText(java.lang.String name)
public void setHasChildren(boolean hasChildren)
hasChildren - boolean flag to set the leafNode propertypublic void supressChildren(boolean hasChildren)
hasChildren - boolean flag to set the leafNode propertypublic boolean equals(StaticOrderedCollectionInterface orderedCollection)
equals in interface StaticOrderedCollectionInterfaceorderedCollection - Another ordered collection to be compared to.
public java.lang.Object get(int index)
get in interface IndexedGetInterfaceindex - the position of the item, zero-based indexing.
java.lang.IndexOutOfBoundsException - if index
is not in the range [0, count()-1].
public int getIndex(java.lang.Object element,
int startIndex)
getIndex in interface StaticOrderedCollectionInterfaceelement - item to search forstartIndex - the position where the search should start
java.lang.IndexOutOfBoundsException - if the index is
not in the range [0..count()-1].
com.sas.util.InvalidElementTypeException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)
public java.util.Enumeration getItems(int start,
int end)
getItems in interface StaticOrderedCollectionInterfacestart - the index of the first item, zero based.end - one past the index of the last item to include in the OrderedCollection, zero based.
Note that the range of elements returned in the Enumeration does not
include the endthe item; this is consistent with substring(start, end)
in java.lang.String, for example.
java.lang.IndexOutOfBoundsException - if start
is not in the range [0, count()-1], or start>last
or end is not in the range [0, count()]
public int getLastIndex(java.lang.Object element,
int startIndex)
getLastIndex in interface StaticOrderedCollectionInterfaceelement - the item to search forstartIndex - the position where the search should start
java.lang.IndexOutOfBoundsException - if the index is
not in the range [0..count()-1]
com.sas.util.InvalidElementTypeException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)public boolean contains(java.lang.Object element)
contains in interface StaticCollectionInterfaceelement - The item to search for
com.sas.util.InvalidElementTypeException - In some implementations,
the objects that are stored may be restricted to a particular
type (such as String). (a RuntimeException)public void apply(com.sas.util.ApplyInterface action)
apply in interface StaticCollectionInterfaceaction - An object that provides a function which takes an
object as an argument and then does something to it.
The application of the action continues until all items in the
the collection have been operated on, of until a call to the
action.apply(Object item) method returns ApplyInterface.ABORT
public void sort(com.sas.util.Comparator comparator,
int start,
int end)
comparator - An instance of a subclass of Comparator which provides a
compare(Object,Object) function.start - the index of the first item in the range to sortend - sort the items between start and (end-1)Comparatorpublic void sort(com.sas.util.Comparator comparator)
comparator - An instance of a subclass of Comparator which provides a
compare(Object,Object) function.Comparatorpublic com.sas.visuals.IconInterface getDefaultIcon()
getDefaultIcon in interface NodeIconInterfacepublic com.sas.visuals.IconInterface getExpandedIcon()
getExpandedIcon in interface NodeIconInterfacepublic com.sas.visuals.IconInterface getSelectedIcon()
getSelectedIcon in interface NodeIconInterfacepublic com.sas.visuals.IconInterface getExpandedSelectedIcon()
getExpandedSelectedIcon in interface NodeIconInterface
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||