|
org.openide.filesystems 6.4.22 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openide.filesystems.FileObject
public abstract class FileObject
This is the base for all implementations of file objects on a filesystem. Provides basic information about the object (its name, parent, whether it exists, etc.) and operations on it (move, delete, etc.).
Constructor Summary | |
---|---|
FileObject()
|
Method Summary | |
---|---|
abstract void |
addFileChangeListener(FileChangeListener fcl)
Add new listener to this object. |
boolean |
canRead()
Tests if this file can be read. |
boolean |
canWrite()
Tests if this file can be written to. |
FileObject |
copy(FileObject target,
String name,
String ext)
Copies this file. |
FileObject |
createData(String name)
Create new data file in this folder with the specified name. |
abstract FileObject |
createData(String name,
String ext)
Create new data file in this folder with the specified name. |
abstract FileObject |
createFolder(String name)
Create a new folder below this one with the specified name. |
void |
delete()
Delete this file. |
abstract void |
delete(FileLock lock)
Delete this file. |
boolean |
existsExt(String ext)
Test whether there is a file with the same basename and only a changed extension in the same folder. |
protected void |
fireFileAttributeChangedEvent(Enumeration en,
FileAttributeEvent fe)
Fire file attribute change event. |
protected void |
fireFileChangedEvent(Enumeration en,
FileEvent fe)
Fire file change event. |
protected void |
fireFileDataCreatedEvent(Enumeration en,
FileEvent fe)
Fire data creation event. |
protected void |
fireFileDeletedEvent(Enumeration en,
FileEvent fe)
Fire file deletion event. |
protected void |
fireFileFolderCreatedEvent(Enumeration en,
FileEvent fe)
Fire folder creation event. |
protected void |
fireFileRenamedEvent(Enumeration en,
FileRenameEvent fe)
Fire file rename event. |
abstract Object |
getAttribute(String attrName)
Get the file attribute with the specified name. |
abstract Enumeration |
getAttributes()
Get all file attribute names for this file. |
abstract FileObject[] |
getChildren()
Get all children of this folder (files and subfolders). |
Enumeration |
getChildren(boolean rec)
Enumerate all children of this folder. |
Enumeration |
getData(boolean rec)
Enumerate all data files in this folder. |
abstract String |
getExt()
Get the extension of this file or folder. |
FileObject |
getFileObject(String relativePath)
Retrieve file or folder relative to a current folder, with a given relative path. |
abstract FileObject |
getFileObject(String name,
String ext)
Retrieve file or folder contained in this folder by name. |
abstract FileSystem |
getFileSystem()
Get the filesystem containing this file. |
Enumeration |
getFolders(boolean rec)
Enumerate the subfolders of this folder. |
abstract InputStream |
getInputStream()
Get input stream. |
String |
getMIMEType()
Get the MIME type of this file. |
abstract String |
getName()
Get the name without extension of this file or folder. |
String |
getNameExt()
Getter for name and extension of a file object. |
abstract OutputStream |
getOutputStream(FileLock lock)
Get output stream. |
String |
getPackageName(char separatorChar)
Deprecated. Please use the ClassPath API instead. |
String |
getPackageNameExt(char separatorChar,
char extSepChar)
Deprecated. Please use the ClassPath API instead. |
abstract FileObject |
getParent()
Get parent folder. |
String |
getPath()
Get the full resource path of this file object starting from the filesystem root. |
abstract long |
getSize()
Get the size of the file. |
URL |
getURL()
Get URL that can be used to access this file. |
boolean |
hasExt(String ext)
Test whether this file has the specified extension. |
abstract boolean |
isData()
Test whether this object is a data object. |
abstract boolean |
isFolder()
Test whether this object is a folder. |
abstract boolean |
isReadOnly()
Deprecated. Please use the canWrite() . |
abstract boolean |
isRoot()
Test whether this object is the root folder. |
abstract boolean |
isValid()
|
boolean |
isVirtual()
Tests if file really exists or is missing. |
abstract Date |
lastModified()
Get last modification time. |
abstract FileLock |
lock()
Lock this file. |
FileObject |
move(FileLock lock,
FileObject target,
String name,
String ext)
Moves this file. |
void |
refresh()
Should check for external modifications. |
void |
refresh(boolean expected)
Should check for external modifications. |
abstract void |
removeFileChangeListener(FileChangeListener fcl)
Remove listener from this object. |
abstract void |
rename(FileLock lock,
String name,
String ext)
Renames this file (or folder). |
abstract void |
setAttribute(String attrName,
Object value)
Set the file attribute with the specified name. |
abstract void |
setImportant(boolean b)
Deprecated. No longer used. Instead use SharabilityQuery . |
String |
toString()
Gets a textual represtentation of this FileObject . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FileObject()
Method Detail |
---|
public abstract String getName()
public abstract String getExt()
public abstract void rename(FileLock lock, String name, String ext) throws IOException
Note that using this call, it is currently only possible to rename within
a parent folder, and not to do moves across folders.
Conversely, implementing filesystems need only implement "simple" renames.
If you wish to move a file across folders, you should call FileUtil.moveFile(org.openide.filesystems.FileObject, org.openide.filesystems.FileObject, java.lang.String)
.
lock
- File must be locked before renaming.name
- new basename of fileext
- new extension of file (ignored for folders)
IOException
public FileObject copy(FileObject target, String name, String ext) throws IOException
target
- target folder to move this file toname
- new basename of fileext
- new extension of file (ignored for folders)
IOException
public FileObject move(FileLock lock, FileObject target, String name, String ext) throws IOException
lock
- File must be locked before renaming.target
- target folder to move this file toname
- new basename of fileext
- new extension of file (ignored for folders)
IOException
public String toString()
FileObject
.
The precise format is not defined. In particular it is probably
not a resource path.
For that purpose use getPath()
directly.
Typically it is useful for debugging purposes. Example of correct usage:
FileObject fo = getSomeFileObject(); ErrorManager.getDefault().log("Got a change from " + fo);
public String getPath()
Subclasses are strongly encouraged to override this method.
Never use this to get a display name for the file! Use FileUtil.getFileDisplayName(org.openide.filesystems.FileObject)
.
Do not use this method to find a file path on disk! Use FileUtil.toFile(org.openide.filesystems.FileObject)
.
FileSystem.findResource(java.lang.String)
public String getPackageNameExt(char separatorChar, char extSepChar)
separatorChar
.
The extension, if present, is separated from the basename with extSepChar
.
Note: fo.getPath() will have the same effect as using this method with / and . (the standard path and extension delimiters).
separatorChar
- char to separate folders and filesextSepChar
- char to separate extension
public String getPackageName(char separatorChar)
getPackageNameExt(char, char)
but omits the extension.
separatorChar
- char to separate folders and files
public String getNameExt()
public abstract FileSystem getFileSystem() throws FileStateInvalidException
Note that it may be possible for a stale file object to exist which refers to a now-defunct filesystem. If this is the case, this method will throw an exception.
FileStateInvalidException
- if the reference to the file
system has been lost (e.g., if the filesystem was deleted)public abstract FileObject getParent()
isFolder()
.
null
if this object isRoot()
.public abstract boolean isFolder()
public abstract Date lastModified()
public abstract boolean isRoot()
public abstract boolean isData()
isFolder()
.
public abstract boolean isValid()
public boolean existsExt(String ext)
getFileObject(String name, String ext)
.
ext
- the alternate extension
public abstract void delete(FileLock lock) throws IOException
lock
- the lock obtained by a call to lock()
IOException
- if the file could not be deletedpublic final void delete() throws IOException
IOException
- if the file could not be deleted or
FileAlreadyLockedException if the file is already locked lock()
public abstract Object getAttribute(String attrName)
attrName
- name of the attribute
null
if the attribute is unset (or could not be properly restored for some reason)public abstract void setAttribute(String attrName, Object value) throws IOException
attrName
- name of the attributevalue
- new value or null
to clear the attribute. Must be serializable, although particular filesystems may or may not use serialization to store attribute values.
IOException
- if the attribute cannot be set. If serialization is used to store it, this may in fact be a subclass such as NotSerializableException
.public abstract Enumeration getAttributes()
public final boolean hasExt(String ext)
ext
- the extension the file should have
.
) is equal to the given extensionpublic abstract void addFileChangeListener(FileChangeListener fcl)
fcl
- the listenerpublic abstract void removeFileChangeListener(FileChangeListener fcl)
fcl
- the listenerprotected void fireFileDataCreatedEvent(Enumeration en, FileEvent fe)
en
- enumeration of FileChangeListener
s that should receive the eventfe
- the event to fire in this objectprotected void fireFileFolderCreatedEvent(Enumeration en, FileEvent fe)
en
- enumeration of FileChangeListener
s that should receive the eventfe
- the event to fire in this objectprotected void fireFileChangedEvent(Enumeration en, FileEvent fe)
en
- enumeration of FileChangeListener
s that should receive the eventfe
- the event to fire in this objectprotected void fireFileDeletedEvent(Enumeration en, FileEvent fe)
en
- enumeration of FileChangeListener
s that should receive the eventfe
- the event to fire in this objectprotected void fireFileAttributeChangedEvent(Enumeration en, FileAttributeEvent fe)
en
- enumeration of FileChangeListener
s that should receive the eventfe
- the event to fire in this objectprotected void fireFileRenamedEvent(Enumeration en, FileRenameEvent fe)
en
- enumeration of FileChangeListener
s that should receive the eventfe
- the event to fire in this objectpublic String getMIMEType()
java.awt.datatransfer
package.
The default implementation calls FileUtil.getMIMEType(java.lang.String)
.
(As a fallback return value, content/unknown
is used.)
"text/plain"
; never null
public abstract long getSize()
public abstract InputStream getInputStream() throws FileNotFoundException
FileNotFoundException
- if the file does not exists, is a folder
rather than a regular file or is invalidpublic abstract OutputStream getOutputStream(FileLock lock) throws IOException
lock
- the lock that belongs to this file (obtained by a call to
lock()
)
IOException
- if an error occures (the file is invalid, etc.)public abstract FileLock lock() throws IOException
FileAlreadyLockedException
- if the file is already locked
UserQuestionException
- in case when the lock cannot be obtained now,
but the underlaying implementation is able to do it after some
complex/dangerous/long-lasting operation and request confirmation
from the user
IOException
public abstract void setImportant(boolean b)
SharabilityQuery
.
For example: Java sources have important .java
files and
unimportant .class
files. If the filesystem provides
an "archive" feature it should archive only .java
files.
b
- true if the file should be considered importantpublic abstract FileObject[] getChildren()
getChildren(boolean)
,
getFolders(boolean)
,
getData(boolean)
public Enumeration getChildren(boolean rec)
rec
- whether to enumerate recursively
FileObject
public Enumeration getFolders(boolean rec)
rec
- whether to recursively list subfolders
FileObject
(satisfying isFolder()
)public Enumeration getData(boolean rec)
rec
- whether to recursively search subfolders
FileObject
(satisfying isData()
)public abstract FileObject getFileObject(String name, String ext)
name
- basename of the file or folder (in this folder)ext
- extension of the file; null
or ""
if the file should have no extension or if folder is requested
null
if the file
or folder does not exist
IllegalArgumentException
- if this
is not a folderpublic FileObject getFileObject(String relativePath)
relativePath
- is just basename of the file or (since 4.16) the relative path delimited by '/'
null
if the file
or folder does not exist
IllegalArgumentException
- if this
is not a folderpublic abstract FileObject createFolder(String name) throws IOException
FileChangeListener.fileFolderCreated(org.openide.filesystems.FileEvent)
.
name
- the name of folder to create. Periods in name are allowed (but no slashes).
IOException
- if the folder cannot be created (e.g. already exists), or if this
is not a folderFileUtil.createFolder(org.openide.filesystems.FileObject, java.lang.String)
public abstract FileObject createData(String name, String ext) throws IOException
FileChangeListener.fileDataCreated(org.openide.filesystems.FileEvent)
.
name
- the name of data object to create (can contain a period, but no slashes)ext
- the extension of the file (or null
or ""
)
IOException
- if the file cannot be created (e.g. already exists), or if this
is not a folderFileUtil.createData(org.openide.filesystems.FileObject, java.lang.String)
public FileObject createData(String name) throws IOException
FileChangeListener.fileDataCreated(org.openide.filesystems.FileEvent)
.
name
- the name of data object to create (can contain a period, but no slashes)
IOException
- if the file cannot be created (e.g. already exists), or if this
is not a folderFileUtil.createData(org.openide.filesystems.FileObject, java.lang.String)
public abstract boolean isReadOnly()
canWrite()
.
The value returned from this method should indicate the capabilities of the file from the point of view of users of the FileObject's API, the actual state of the file on a disk does not matter if the implementation of the filesystem can change it when requested.
The result returned from this method should be tight together with
the expected behaviour of getOutputStream
. If it is
likely that the method successfully returns a stream that can be
written to, let the isReadOnly
return false
.
Also other fileobject methods like delete
are suggested to be connected to result of this method. If not
read only, then it can be deleted, etc.
It is a good idea to call this method before attempting to perform any operation on the FileObject that might throw an IOException simply because it is read-only. If isReadOnly returns true, the operation may be skipped, or the user notified that it cannot be done. However it is often desirable for the user to be able to continue the operation in case the filesystem supports making a file writable. In this case calling code should:
lock()
and catch any exception thrown.
UserQuestionException
is thrown,
call UserQuestionException.confirmed()
on it
(asynchronously - do not block any important threads). If true
,
proceed with the operation. If false
, exit.
If an IOException
is thrown, notify it and exit.
IOException
is thrown, call isReadOnly()
.
If true
, ignore the exception (it is expected).
If false
, notify it.
true
if file is read-onlypublic boolean canWrite()
The default implementation simply uses java.io.File.canWrite
if there exists conversion to java.io.File
(see FileUtil.toFile(org.openide.filesystems.FileObject)
).
If conversion is not possible, then deprecated method isReadOnly()
is used.
public boolean canRead()
The default implementation simply uses java.io.File.canRead
if there exists conversion to java.io.File
(see FileUtil.toFile(org.openide.filesystems.FileObject)
).
If conversion is not possible, then true
is returned.
public void refresh(boolean expected)
expected
- should the file events be marked as expected change or not?FileEvent.isExpected()
public void refresh()
The file events are marked as unexpected.
public final URL getURL() throws FileStateInvalidException
FileStateInvalidException
- if the file is not validURLMapper.findURL(org.openide.filesystems.FileObject, int)
,
URLMapper.INTERNAL
public boolean isVirtual()
|
org.openide.filesystems 6.4.22 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |