public abstract class AbstractFileObject extends Object implements FileObject
Modifier | Constructor and Description |
---|---|
protected |
AbstractFileObject(AbstractFileName name,
AbstractFileSystem fs) |
Modifier and Type | Method and Description |
---|---|
boolean |
canRenameTo(FileObject newfile)
Queries the object if a simple rename to the filename of
newfile
is possible. |
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 FileContent |
doCreateFileContent()
Create a FileContent implementation.
|
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<String,Object> |
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.E.g. |
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 |
doRemoveAttribute(String attrName)
Removes an attribute of this file.
|
protected void |
doRename(FileObject newfile)
Renames the file.
|
protected void |
doSetAttribute(String attrName,
Object value)
Sets an attribute of this file.
|
protected boolean |
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<FileObject> 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.
This will only happen if you monitor the file using FileMonitor . |
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 an 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.E.g. |
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.
|
protected AbstractFileObject(AbstractFileName name, AbstractFileSystem fs)
name
- the file name - muse be an instance of AbstractFileName
fs
- the file systemClassCastException
- if name
is not an instance of AbstractFileName
protected void doAttach() throws Exception
Exception
- if an error occurs.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
- if an error occurs.protected abstract FileType doGetType() throws Exception
Exception
- if an error occurs.protected boolean doIsHidden() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns false.Exception
- if an error occurs.protected boolean doIsReadable() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns true.Exception
- if an error occurs.protected boolean doIsWriteable() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns true.Exception
- if an error occurs.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
- if an error occurs.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
- if an error occurs.protected void doDelete() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
doIsWriteable()
returns true.
Exception
- if an error occurs.protected void doRename(FileObject newfile) throws Exception
doIsWriteable()
returns true.
newfile
- A FileObject with the new file name.Exception
- if an error occurs.protected void doCreateFolder() throws Exception
doGetType()
returns FileType.IMAGINARY
.
Exception
- if an error occurs.protected void onChildrenChanged(FileName child, FileType newType) throws Exception
child
- The name of the child that changed.newType
- The type of the file.Exception
- if an error occurs.protected void onChange() throws Exception
Exception
- if an error occurs.protected long doGetLastModifiedTime() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.Exception
- if an error occurs.protected boolean doSetLastModifiedTime(long modtime) throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.modtime
- The last modification time.Exception
- if an error occurs.protected Map<String,Object> doGetAttributes() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns an empty map.Exception
- if an error occurs.protected void doSetAttribute(String attrName, Object value) throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.attrName
- The attribute name.value
- The value to be associated with the attribute name.Exception
- if an error occurs.protected void doRemoveAttribute(String attrName) throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.attrName
- The name of the attribute to remove.Exception
- if an error occurs.protected Certificate[] doGetCertificates() throws Exception
doGetType()
does not return FileType.IMAGINARY
.
This implementation always returns null.Exception
- if an error occurs.protected abstract long doGetContentSize() throws Exception
doGetType()
returns FileType.FILE
.Exception
- if an error occurs.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
- if an error occurs.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.
mode
- The mode to access the file.Exception
- if an error occurs.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.bAppend
- true if the file should be appended to, false if it should be overwritten.Exception
- if an error occurs.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
- if an error occurs.public boolean exists() throws FileSystemException
exists
in interface FileObject
FileSystemException
- if an error occurs.public FileType getType() throws FileSystemException
getType
in interface FileObject
FileSystemException
- if an error occurs.public boolean isHidden() throws FileSystemException
isHidden
in interface FileObject
FileSystemException
- if an error occurs.public boolean isReadable() throws FileSystemException
isReadable
in interface FileObject
FileSystemException
- if an error occurs.public boolean isWriteable() throws FileSystemException
isWriteable
in interface FileObject
FileSystemException
- if an error occurs.public FileObject getParent() throws FileSystemException
getParent
in interface FileObject
FileSystemException
- if an error occurs.public FileObject[] getChildren() throws FileSystemException
getChildren
in interface FileObject
FileSystemException
- if an error occurs.public FileObject getChild(String name) throws FileSystemException
getChild
in interface FileObject
name
- The name of the child to locate.FileSystemException
- if an error occurs.public FileObject resolveFile(String name, NameScope scope) throws FileSystemException
resolveFile
in interface FileObject
name
- The name of the child to locate.scope
- the NameScope.FileSystemException
- if an error occurs.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
- if an error occurs.public boolean delete() throws FileSystemException
delete
in interface FileObject
FileSystemException
- if an error occurs.public int delete(FileSelector selector) throws FileSystemException
delete
in interface FileObject
selector
- The FileSelector.FileSystemException
- if an error occurs.public void createFile() throws FileSystemException
createFile
in interface FileObject
FileSystemException
- if an error occurs.public void createFolder() throws FileSystemException
createFolder
in interface FileObject
FileSystemException
- if an error occurs.public void copyFrom(FileObject file, FileSelector selector) throws FileSystemException
copyFrom
in interface FileObject
file
- The FileObject to copy.selector
- The FileSelector.FileSystemException
- if an error occurs.public void moveTo(FileObject destFile) throws FileSystemException
moveTo
in interface FileObject
destFile
- The target FileObject.FileSystemException
- if an error occurs.protected boolean isSameFile(FileObject destFile) throws FileSystemException
destFile
just with a different
name.destFile
- The file to compare to.FileSystemException
- if an error occurs.protected boolean doIsSameFile(FileObject destFile) throws FileSystemException
destFile
just with a different
name.destFile
- The file to compare to.FileSystemException
- if an error occurs.public boolean canRenameTo(FileObject newfile)
newfile
is possible.canRenameTo
in interface FileObject
newfile
- the new filenamepublic FileObject[] findFiles(FileSelector selector) throws FileSystemException
findFiles
in interface FileObject
selector
- The FileSelector.FileSystemException
- if an error occurs.public FileContent getContent() throws FileSystemException
getContent
in interface FileObject
FileSystemException
- if an error occurs.protected FileContent doCreateFileContent() throws FileSystemException
FileSystemException
- if an error occurs.public void refresh() throws FileSystemException
refresh
in interface FileObject
FileSystemException
- if an error occurs.public void close() throws FileSystemException
close
in interface FileObject
FileSystemException
- if an error occurs.FileContent.close()
public InputStream getInputStream() throws FileSystemException
FileSystemException
- if an error occurs.public RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
mode
- The RandomAccessMode.FileSystemException
- if an error occurs.public OutputStream getOutputStream() throws FileSystemException
FileSystemException
- if an error occurs.public OutputStream getOutputStream(boolean bAppend) throws FileSystemException
bAppend
- true when append to the file.FileSystemException
- if an error occurs.protected void endOutput() throws Exception
Exception
- if an error occurs.protected void handleCreate(FileType newType) throws Exception
newType
- The type of the file.Exception
- if an error occurs.protected void handleDelete() throws Exception
Exception
- if an error occurs.protected void handleChanged() throws Exception
FileMonitor
.Exception
- if an error occurs.protected void childrenChanged(FileName childName, FileType newType) throws Exception
childName
- The name of the child.newType
- The type of the child.Exception
- if an error occurs.public void findFiles(FileSelector selector, boolean depthwise, List<FileObject> selected) throws FileSystemException
findFiles
in interface FileObject
selector
- The FileSelector.depthwise
- if true files are added after their descendants, before otherwise.selected
- A List of the located FileObjects.FileSystemException
- if an error occurs.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
- The Object to add.protected void notifyAllStreamsClosed()
public FileOperations getFileOperations() throws FileSystemException
getFileOperations
in interface FileObject
FileSystemException
- if an error occurs.Copyright © 2002-2016 The Apache Software Foundation. All Rights Reserved.