|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.vfs.provider.AbstractFileObject
A partial file object implementation.
Constructor Summary | |
protected |
AbstractFileObject(FileName name,
AbstractFileSystem fs)
|
Method Summary | |
boolean |
canRenameTo(FileObject newfile)
Queries the object if a simple rename to the filename of newfile
is possible. |
protected void |
childrenChanged()
Deprecated. use childrenChanged(FileName,FileType) |
protected void |
childrenChanged(FileName childName,
FileType newType)
Notifies the file that its children have changed. |
void |
close()
Closes this file, and its content. |
void |
copyFrom(FileObject file,
FileSelector selector)
Copies another file to this file. |
void |
createFile()
Creates this file, if it does not exist. |
void |
createFolder()
Creates this folder, if it does not exist. |
boolean |
delete()
Deletes this file. |
int |
delete(FileSelector selector)
Deletes this file, and all children. |
protected void |
doAttach()
Attaches this file object to its file resource. |
protected void |
doCreateFolder()
Creates this file as a folder. |
protected void |
doDelete()
Deletes the file. |
protected void |
doDetach()
Detaches this file object from its file resource. |
protected Map |
doGetAttributes()
Returns the attributes of this file. |
protected Certificate[] |
doGetCertificates()
Returns the certificates used to sign this file. |
protected abstract long |
doGetContentSize()
Returns the size of the file content (in bytes). |
protected abstract InputStream |
doGetInputStream()
Creates an input stream to read the file content from. |
protected long |
doGetLastModifiedTime()
Returns the last modified time of this file. |
protected OutputStream |
doGetOutputStream(boolean bAppend)
Creates an output stream to write the file content to. |
protected RandomAccessContent |
doGetRandomAccessContent(RandomAccessMode mode)
Creates access to the file for random i/o. |
protected abstract FileType |
doGetType()
Determines the type of this file. |
protected boolean |
doIsHidden()
Determines if this file is hidden. |
protected boolean |
doIsReadable()
Determines if this file can be read. |
protected boolean |
doIsSameFile(FileObject destFile)
Checks if this fileObject is the same file as destFile just with a different
name. |
protected boolean |
doIsWriteable()
Determines if this file can be written to. |
protected abstract String[] |
doListChildren()
Lists the children of this file. |
protected FileObject[] |
doListChildrenResolved()
Lists the children of this file. |
protected void |
doRename(FileObject newfile)
Renames the file. |
protected void |
doSetAttribute(String atttrName,
Object value)
Sets an attribute of this file. |
protected void |
doSetLastModifiedTime(long modtime)
Sets the last modified time of this file. |
protected void |
endOutput()
Called when the ouput stream for this file is closed. |
boolean |
exists()
Determines if the file exists. |
protected void |
finalize()
|
FileObject[] |
findFiles(FileSelector selector)
Finds the set of matching descendents of this file, in depthwise order. |
void |
findFiles(FileSelector selector,
boolean depthwise,
List selected)
Traverses the descendents of this file, and builds a list of selected files. |
FileObject |
getChild(String name)
Returns a child of this file. |
FileObject[] |
getChildren()
Returns the children of the file. |
FileContent |
getContent()
Returns the file's content. |
protected FileContentInfoFactory |
getFileContentInfoFactory()
create the filecontentinfo implementation |
FileOperations |
getFileOperations()
|
FileSystem |
getFileSystem()
Returns the file system this file belongs to. |
InputStream |
getInputStream()
Returns an input stream to use to read the content of the file. |
FileName |
getName()
Returns the name of the file. |
OutputStream |
getOutputStream()
Prepares this file for writing. |
OutputStream |
getOutputStream(boolean bAppend)
Prepares this file for writing. |
FileObject |
getParent()
Returns the parent of the file. |
RandomAccessContent |
getRandomAccessContent(RandomAccessMode mode)
Returns an input/output stream to use to read and write the content of the file in and random manner. |
FileType |
getType()
Returns the file's type. |
URL |
getURL()
Returns a URL representation of the file. |
protected void |
handleChanged()
Called when this file is changed. |
protected void |
handleCreate(FileType newType)
Called when this file is created. |
protected void |
handleDelete()
Called when this file is deleted. |
void |
holdObject(Object strongRef)
This method is meant to add a object where this object holds a strong reference then. |
protected void |
injectType(FileType fileType)
|
boolean |
isAttached()
Check if the internal state is "attached" |
boolean |
isContentOpen()
Check if the content stream is open |
boolean |
isHidden()
Determines if this file can be read. |
boolean |
isReadable()
Determines if this file can be read. |
protected boolean |
isSameFile(FileObject destFile)
Checks if this fileObject is the same file as destFile just with a different
name. |
boolean |
isWriteable()
Determines if this file can be written to. |
void |
moveTo(FileObject destFile)
Moves (rename) the file to another one |
protected void |
notifyAllStreamsClosed()
will be called after this file-object closed all its streams. |
protected void |
onChange()
Called when the type or content of this file changes. |
protected void |
onChildrenChanged(FileName child,
FileType newType)
Called when the children of this file change. |
void |
refresh()
This will prepare the fileObject to get resynchronized with the underlaying filesystem if required |
FileObject |
resolveFile(String path)
Finds a file, relative to this file. |
FileObject |
resolveFile(String name,
NameScope scope)
Returns a child by name. |
String |
toString()
Returns the URI of the file. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected AbstractFileObject(FileName name, AbstractFileSystem fs)
Method Detail |
protected void doAttach() throws Exception
Exception
protected void doDetach() throws Exception
Called when this file is closed. Note that the file object may be reused later, so should be able to be reattached.
This implementation does nothing.
Exception
protected abstract FileType doGetType() throws Exception
Exception
protected boolean doIsHidden() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns false.
Exception
protected boolean doIsReadable() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns true.
Exception
protected boolean doIsWriteable() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns true.
Exception
protected abstract String[] doListChildren() throws Exception
doGetType()
returns FileType.FOLDER
. The return value of this method
is cached, so the implementation can be expensive.
Exception
protected FileObject[] doListChildrenResolved() throws Exception
doGetType()
returns FileType.FOLDER
. The return value of this method
is cached, so the implementation can be expensive.doListChildren
you could return FileObject's to e.g. reinitialize the type of the file.
Exception
protected void doDelete() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
doIsWriteable()
returns true.
Exception
protected void doRename(FileObject newfile) throws Exception
doIsWriteable()
returns true.
Exception
protected void doCreateFolder() throws Exception
doGetType()
returns FileType.IMAGINARY
.
Exception
protected void onChildrenChanged(FileName child, FileType newType) throws Exception
Exception
protected void onChange() throws Exception
Exception
protected long doGetLastModifiedTime() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.
Exception
protected void doSetLastModifiedTime(long modtime) throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.
Exception
protected Map doGetAttributes() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns an empty map.
Exception
protected void doSetAttribute(String atttrName, Object value) throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.
Exception
protected Certificate[] doGetCertificates() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns null.
Exception
protected abstract long doGetContentSize() throws Exception
doGetType()
returns FileType.FILE
.
Exception
protected abstract InputStream doGetInputStream() throws Exception
doGetType()
returns FileType.FILE
.
It is guaranteed that there are no open output streams for this file when this method is called.
The returned stream does not have to be buffered.
Exception
protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode) throws Exception
doGetType()
returns FileType.FILE
.
It is guaranteed that there are no open output streams for this file when this method is called.
Exception
protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
doIsWriteable()
returns true.
doGetType()
returns FileType.FILE
, or
doGetType()
returns FileType.IMAGINARY
, and the file's
parent exists and is a folder.
It is guaranteed that there are no open stream (input or output) for this file when this method is called.
The returned stream does not have to be buffered.
This implementation throws an exception.
Exception
public String toString()
public FileName getName()
getName
in interface FileObject
public FileSystem getFileSystem()
getFileSystem
in interface FileObject
public URL getURL() throws FileSystemException
getURL
in interface FileObject
FileSystemException
public boolean exists() throws FileSystemException
exists
in interface FileObject
true
if this file exists, false
if not.
FileSystemException
- On error determining if this file exists.public FileType getType() throws FileSystemException
getType
in interface FileObject
FileType
constants. Never returns null.
FileSystemException
- On error determining the file's type.public boolean isHidden() throws FileSystemException
isHidden
in interface FileObject
true
if this file is hidden, false
if not.
FileSystemException
- On error determining if this file exists.public boolean isReadable() throws FileSystemException
isReadable
in interface FileObject
true
if this file is readable, false
if not.
FileSystemException
- On error determining if this file exists.public boolean isWriteable() throws FileSystemException
isWriteable
in interface FileObject
true
if this file is writeable, false
if not.
FileSystemException
- On error determining if this file exists.public FileObject getParent() throws FileSystemException
getParent
in interface FileObject
FileSystemException
- On error finding the file's parent.public FileObject[] getChildren() throws FileSystemException
getChildren
in interface FileObject
FileSystemException
- If this file does not exist, or is not a folder, or on error
listing this file's children.public FileObject getChild(String name) throws FileSystemException
getChild
in interface FileObject
name
- The name of the child.
FileSystemException
- If this file does not exist, or is not a folder, or on error
determining this file's children.public FileObject resolveFile(String name, NameScope scope) throws FileSystemException
resolveFile
in interface FileObject
name
- The name to resolve.
FileSystemException
- On error parsing the path, or on error finding the file.public FileObject resolveFile(String path) throws FileSystemException
resolveFile
in interface FileObject
path
- The path of the file to locate. Can either be a relative
path, which is resolved relative to this file, or an
absolute path, which is resolved relative to the file system
that contains this file.
FileSystemException
- On error parsing the path, or on error finding the file.public boolean delete() throws FileSystemException
delete
in interface FileObject
FileSystemException
- If this file is a non-empty folder, or if this file is read-only,
or on error deleteing this file.public int delete(FileSelector selector) throws FileSystemException
delete
in interface FileObject
selector
- The selector to use to select which files to delete.
FileSystemException
- If this file or one of its descendents is read-only, or on error
deleting this file or one of its descendents.public void createFile() throws FileSystemException
createFile
in interface FileObject
FileSystemException
- If the file already exists with the wrong type, or the parent
folder is read-only, or on error creating this file or one of
its ancestors.public void createFolder() throws FileSystemException
createFolder
in interface FileObject
FileSystemException
- If the folder already exists with the wrong type, or the parent
folder is read-only, or on error creating this folder or one of
its ancestors.public void copyFrom(FileObject file, FileSelector selector) throws FileSystemException
copyFrom
in interface FileObject
file
- The source file to copy.selector
- The selector to use to select which files to copy.
FileSystemException
- If this file is read-only, or if the source file does not exist,
or on error copying the file.public void moveTo(FileObject destFile) throws FileSystemException
moveTo
in interface FileObject
destFile
- the New filename.
FileSystemException
- If this file is read-only, or if the source file does not exist,
or on error copying the file.protected boolean isSameFile(FileObject destFile) throws FileSystemException
destFile
just with a different
name.
FileSystemException
protected boolean doIsSameFile(FileObject destFile) throws FileSystemException
destFile
just with a different
name.
FileSystemException
public boolean canRenameTo(FileObject newfile)
newfile
is possible.
canRenameTo
in interface FileObject
newfile
- the new filename
public FileObject[] findFiles(FileSelector selector) throws FileSystemException
findFiles
in interface FileObject
selector
- The selector to use to select matching files.
FileSystemException
public FileContent getContent() throws FileSystemException
getContent
in interface FileObject
FileSystemException
- On error getting this file's content.public void refresh() throws FileSystemException
refresh
in interface FileObject
FileSystemException
public void close() throws FileSystemException
close
in interface FileObject
FileSystemException
- On error closing the file.FileContent.close()
public InputStream getInputStream() throws FileSystemException
FileSystemException
public RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
FileSystemException
public OutputStream getOutputStream() throws FileSystemException
FileSystemException
public OutputStream getOutputStream(boolean bAppend) throws FileSystemException
bAppend
- true when append to the file.FileSystemException
protected void endOutput() throws Exception
Exception
protected void handleCreate(FileType newType) throws Exception
Exception
protected void handleDelete() throws Exception
Exception
protected void handleChanged() throws Exception
FileMonitor
.
Exception
protected void childrenChanged() throws Exception
childrenChanged(FileName,FileType)
Exception
protected void childrenChanged(FileName childName, FileType newType) throws Exception
Exception
public void findFiles(FileSelector selector, boolean depthwise, List selected) throws FileSystemException
findFiles
in interface FileObject
selector
- the selector used to determine if the file should be selecteddepthwise
- controls the ordering in the list. e.g. deepest firstselected
- container for selected files. list needs not to be empty.
FileSystemException
public boolean isContentOpen()
isContentOpen
in interface FileObject
public boolean isAttached()
isAttached
in interface FileObject
protected FileContentInfoFactory getFileContentInfoFactory()
protected void injectType(FileType fileType)
public void holdObject(Object strongRef)
strongRef
- protected void notifyAllStreamsClosed()
public FileOperations getFileOperations() throws FileSystemException
getFileOperations
in interface FileObject
FileSystemException
protected void finalize() throws Throwable
Throwable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |