Class AbstractFileObject<AFS extends AbstractFileSystem>
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileObject<AFS>
-
- Type Parameters:
AFS
- An AbstractFileSystem subclass
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Comparable<FileObject>
,java.lang.Iterable<FileObject>
,FileObject
- Direct Known Subclasses:
CompressedFileFileObject
,DelegateFileObject
,FtpFileObject
,HttpFileObject
,LocalFile
,RamFileObject
,SftpFileObject
,TarFileObject
,UrlFileObject
,ZipFileObject
public abstract class AbstractFileObject<AFS extends AbstractFileSystem> extends java.lang.Object implements FileObject
A partial file object implementation.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFileObject(AbstractFileName name, AFS fs)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canRenameTo(FileObject newfile)
Queries the object if a simple rename to the filename ofnewfile
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.int
compareTo(FileObject file)
Compares two FileObjects (ignores case).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 matching theselector
.int
deleteAll()
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 java.util.Map<java.lang.String,java.lang.Object>
doGetAttributes()
Returns the attributes of this file.protected java.security.cert.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 java.io.InputStream
doGetInputStream()
Creates an input stream to read the file content from.protected long
doGetLastModifiedTime()
Returns the last modified time of this file.protected java.io.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
doIsExecutable()
Determines if this file is executable.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 asdestFile
just with a different name.protected boolean
doIsWriteable()
Determines if this file can be written to.protected abstract java.lang.String[]
doListChildren()
Lists the children of this file.protected FileObject[]
doListChildrenResolved()
Lists the children of this file.protected void
doRemoveAttribute(java.lang.String attrName)
Removes an attribute of this file.protected void
doRename(FileObject newFile)
Renames the file.protected void
doSetAttribute(java.lang.String attrName, java.lang.Object value)
Sets an attribute of this file.protected boolean
doSetExecutable(boolean executable, boolean ownerOnly)
Make the file executable.protected boolean
doSetLastModifiedTime(long modtime)
Sets the last modified time of this file.protected boolean
doSetReadable(boolean readable, boolean ownerOnly)
Make the file or folder readable.protected boolean
doSetWritable(boolean writable, boolean ownerOnly)
Make the file or folder writeable.protected void
endOutput()
Called when the output 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 descendants of this file, in depthwise order.void
findFiles(FileSelector selector, boolean depthwise, java.util.List<FileObject> selected)
Traverses the descendants of this file, and builds a list of selected files.protected AFS
getAbstractFileSystem()
Returns the file system this file belongs to.FileObject
getChild(java.lang.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()
Creates the FileContentInfo factory.FileOperations
getFileOperations()
FileSystem
getFileSystem()
Returns the file system this file belongs to.java.io.InputStream
getInputStream()
Returns an input stream to use to read the content of the file.FileName
getName()
Returns the name of the file.java.io.OutputStream
getOutputStream()
Prepares this file for writing.java.io.OutputStream
getOutputStream(boolean bAppend)
Prepares this file for writing.FileObject
getParent()
Returns the parent of the file.java.lang.String
getPublicURIString()
Returns the receiver as a URI String for public display, like, without a password.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.java.net.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(java.lang.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
isExecutable()
Determines if this file is executable.boolean
isFile()
Checks if this file is a regular file by using its file type.boolean
isFolder()
Checks if this file is a folder by using its file type.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 asdestFile
just with a different name.boolean
isWriteable()
Determines if this file can be written to.java.util.Iterator<FileObject>
iterator()
Returns an iterator over a set of all FileObject in this file object.java.util.List<FileObject>
listFiles(FileSelector selector)
Lists the set of matching descendants of this file, in depthwise order.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 underlying filesystem if required.FileObject
resolveFile(java.lang.String path)
Finds a file, relative to this file.FileObject
resolveFile(java.lang.String name, NameScope scope)
Returns a child by name.boolean
setExecutable(boolean readable, boolean ownerOnly)
Sets the owner's (or everybody's) write permission.boolean
setReadable(boolean readable, boolean ownerOnly)
Sets the owner's (or everybody's) read permission.boolean
setWritable(boolean readable, boolean ownerOnly)
Sets the owner's (or everybody's) write permission.java.lang.String
toString()
Returns the URI as a String.
-
-
-
Constructor Detail
-
AbstractFileObject
protected AbstractFileObject(AbstractFileName name, AFS fs)
- Parameters:
name
- the file name - muse be an instance ofAbstractFileName
fs
- the file system- Throws:
java.lang.ClassCastException
- ifname
is not an instance ofAbstractFileName
-
-
Method Detail
-
canRenameTo
public boolean canRenameTo(FileObject newfile)
Queries the object if a simple rename to the filename ofnewfile
is possible.- Specified by:
canRenameTo
in interfaceFileObject
- Parameters:
newfile
- the new filename- Returns:
- true if rename is possible
-
childrenChanged
protected void childrenChanged(FileName childName, FileType newType) throws java.lang.Exception
Notifies the file that its children have changed.- Parameters:
childName
- The name of the child.newType
- The type of the child.- Throws:
java.lang.Exception
- if an error occurs.
-
close
public void close() throws FileSystemException
Closes this file, and its content.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceFileObject
- Throws:
FileSystemException
- if an error occurs.- See Also:
FileContent.close()
-
compareTo
public int compareTo(FileObject file)
Compares two FileObjects (ignores case).- Specified by:
compareTo
in interfacejava.lang.Comparable<AFS extends AbstractFileSystem>
- Parameters:
file
- the object to compare.- Returns:
- a negative integer, zero, or a positive integer when this object is less than, equal to, or greater than the given object.
-
copyFrom
public void copyFrom(FileObject file, FileSelector selector) throws FileSystemException
Copies another file to this file.- Specified by:
copyFrom
in interfaceFileObject
- Parameters:
file
- The FileObject to copy.selector
- The FileSelector.- Throws:
FileSystemException
- if an error occurs.
-
createFile
public void createFile() throws FileSystemException
Creates this file, if it does not exist.- Specified by:
createFile
in interfaceFileObject
- Throws:
FileSystemException
- if an error occurs.
-
createFolder
public void createFolder() throws FileSystemException
Creates this folder, if it does not exist. Also creates any ancestor files which do not exist.- Specified by:
createFolder
in interfaceFileObject
- Throws:
FileSystemException
- if an error occurs.
-
delete
public boolean delete() throws FileSystemException
Deletes this file.TODO - This will not fail if this is a non-empty folder.
- Specified by:
delete
in interfaceFileObject
- Returns:
- true if this object has been deleted
- Throws:
FileSystemException
- if an error occurs.
-
delete
public int delete(FileSelector selector) throws FileSystemException
Deletes this file, and all children matching theselector
.- Specified by:
delete
in interfaceFileObject
- Parameters:
selector
- The FileSelector.- Returns:
- the number of deleted files.
- Throws:
FileSystemException
- if an error occurs.
-
deleteAll
public int deleteAll() throws FileSystemException
Deletes this file and all children. Shorthand fordelete(Selectors.SELECT_ALL)
- Specified by:
deleteAll
in interfaceFileObject
- Returns:
- the number of deleted files.
- Throws:
FileSystemException
- if an error occurs.- See Also:
delete(FileSelector)
,Selectors.SELECT_ALL
-
doAttach
protected void doAttach() throws java.lang.Exception
Attaches this file object to its file resource.This method is called before any of the doBlah() or onBlah() methods. Sub-classes can use this method to perform lazy initialisation.
This implementation does nothing.
- Throws:
java.lang.Exception
- if an error occurs.
-
doCreateFileContent
protected FileContent doCreateFileContent() throws FileSystemException
Create a FileContent implementation.- Returns:
- The FileContent.
- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.0
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Creates this file as a folder. Is only called when:doGetType()
returnsFileType.IMAGINARY
.- The parent folder exists and is writeable, or this file is the root of the file system.
- Throws:
java.lang.Exception
- if an error occurs.
-
doDelete
protected void doDelete() throws java.lang.Exception
Deletes the file. Is only called when:doGetType()
does not returnFileType.IMAGINARY
.doIsWriteable()
returns true.- This file has no children, if a folder.
- Throws:
java.lang.Exception
- if an error occurs.
-
doDetach
protected void doDetach() throws java.lang.Exception
Detaches this file object from its file resource.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.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetAttributes
protected java.util.Map<java.lang.String,java.lang.Object> doGetAttributes() throws java.lang.Exception
Returns the attributes of this file. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation always returns an empty map.
- Returns:
- The attributes of the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetCertificates
protected java.security.cert.Certificate[] doGetCertificates() throws java.lang.Exception
Returns the certificates used to sign this file. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation always returns null.
- Returns:
- The certificates used to sign the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetContentSize
protected abstract long doGetContentSize() throws java.lang.Exception
Returns the size of the file content (in bytes). Is only called ifdoGetType()
returnsFileType.FILE
.- Returns:
- The size of the file in bytes.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetInputStream
protected abstract java.io.InputStream doGetInputStream() throws java.lang.Exception
Creates an input stream to read the file content from. Is only called ifdoGetType()
returnsFileType.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.
- Returns:
- An InputStream to read the file content.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws java.lang.Exception
Returns the last modified time of this file. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation throws an exception.
- Returns:
- The last modification time.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetOutputStream
protected java.io.OutputStream doGetOutputStream(boolean bAppend) throws java.lang.Exception
Creates an output stream to write the file content to. Is only called if:doIsWriteable()
returns true.doGetType()
returnsFileType.FILE
, ordoGetType()
returnsFileType.IMAGINARY
, and the file's parent exists and is a folder.
The returned stream does not have to be buffered.
This implementation throws an exception.
- Parameters:
bAppend
- true if the file should be appended to, false if it should be overwritten.- Returns:
- An OutputStream to write to the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetRandomAccessContent
protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode) throws java.lang.Exception
Creates access to the file for random i/o. Is only called ifdoGetType()
returnsFileType.FILE
.It is guaranteed that there are no open output streams for this file when this method is called.
- Parameters:
mode
- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetType
protected abstract FileType doGetType() throws java.lang.Exception
Determines the type of this file. Must not return null. The return value of this method is cached, so the implementation can be expensive.- Returns:
- the type of the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsExecutable
protected boolean doIsExecutable() throws java.lang.Exception
Determines if this file is executable. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation always returns false.
- Returns:
- true if the file is executable, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsHidden
protected boolean doIsHidden() throws java.lang.Exception
Determines if this file is hidden. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation always returns false.
- Returns:
- true if the file is hidden, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsReadable
protected boolean doIsReadable() throws java.lang.Exception
Determines if this file can be read. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation always returns true.
- Returns:
- true if the file is readable, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsSameFile
protected boolean doIsSameFile(FileObject destFile) throws FileSystemException
Checks if this fileObject is the same file asdestFile
just with a different name. E.g. for case insensitive filesystems like windows.- Parameters:
destFile
- The file to compare to.- Returns:
- true if the FileObjects are the same.
- Throws:
FileSystemException
- if an error occurs.
-
doIsWriteable
protected boolean doIsWriteable() throws java.lang.Exception
Determines if this file can be written to. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.This implementation always returns true.
- Returns:
- true if the file is writable.
- Throws:
java.lang.Exception
- if an error occurs.
-
doListChildren
protected abstract java.lang.String[] doListChildren() throws java.lang.Exception
Lists the children of this file. Is only called ifdoGetType()
returnsFileType.FOLDER
. The return value of this method is cached, so the implementation can be expensive.- Returns:
- a possible empty String array if the file is a directory or null or an exception if the file is not a directory or can't be read.
- Throws:
java.lang.Exception
- if an error occurs.
-
doListChildrenResolved
protected FileObject[] doListChildrenResolved() throws java.lang.Exception
Lists the children of this file.Is only called if
doGetType()
returnsFileType.FOLDER
.The return value of this method is cached, so the implementation can be expensive.
Other thandoListChildren
you could return FileObject's to e.g. reinitialize the type of the file.(Introduced for Webdav: "permission denied on resource" during getType())
- Returns:
- The children of this FileObject.
- Throws:
java.lang.Exception
- if an error occurs.
-
doRemoveAttribute
protected void doRemoveAttribute(java.lang.String attrName) throws java.lang.Exception
Removes an attribute of this file.Is only called if
doGetType()
does not returnFileType.IMAGINARY
.This implementation throws an exception.
- Parameters:
attrName
- The name of the attribute to remove.- Throws:
java.lang.Exception
- if an error occurs.- Since:
- 2.0
-
doRename
protected void doRename(FileObject newFile) throws java.lang.Exception
Renames the file.Is only called when:
doIsWriteable()
returns true.
This implementation throws an exception.
- Parameters:
newFile
- A FileObject with the new file name.- Throws:
java.lang.Exception
- if an error occurs.
-
doSetAttribute
protected void doSetAttribute(java.lang.String attrName, java.lang.Object value) throws java.lang.Exception
Sets an attribute of this file.Is only called if
doGetType()
does not returnFileType.IMAGINARY
.This implementation throws an exception.
- Parameters:
attrName
- The attribute name.value
- The value to be associated with the attribute name.- Throws:
java.lang.Exception
- if an error occurs.
-
doSetExecutable
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws java.lang.Exception
Make the file executable.Only called if
doGetType()
does not returnFileType.IMAGINARY
.This implementation returns false.
- Parameters:
executable
- True to allow access, false to disallow.ownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded.
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- Since:
- 2.1
- See Also:
setExecutable(boolean, boolean)
-
doSetLastModifiedTime
protected boolean doSetLastModifiedTime(long modtime) throws java.lang.Exception
Sets the last modified time of this file.Is only called if
doGetType()
does not returnFileType.IMAGINARY
.This implementation throws an exception.
- Parameters:
modtime
- The last modification time.- Returns:
- true if the time was set.
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.
-
doSetReadable
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws java.lang.Exception
Make the file or folder readable.Only called if
doGetType()
does not returnFileType.IMAGINARY
.This implementation returns false.
- Parameters:
readable
- True to allow access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- Since:
- 2.1
- See Also:
setReadable(boolean, boolean)
-
doSetWritable
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws java.lang.Exception
Make the file or folder writeable.Only called if
doGetType()
does not returnFileType.IMAGINARY
.- Parameters:
writable
- True to allow access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- Since:
- 2.1
- See Also:
setWritable(boolean, boolean)
-
endOutput
protected void endOutput() throws java.lang.Exception
Called when the output stream for this file is closed.- Throws:
java.lang.Exception
- if an error occurs.
-
exists
public boolean exists() throws FileSystemException
Determines if the file exists.- Specified by:
exists
in interfaceFileObject
- Returns:
- true if the file exists, false otherwise,
- Throws:
FileSystemException
- if an error occurs.
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
findFiles
public FileObject[] findFiles(FileSelector selector) throws FileSystemException
Finds the set of matching descendants of this file, in depthwise order.- Specified by:
findFiles
in interfaceFileObject
- Parameters:
selector
- The FileSelector.- Returns:
- list of files or null if the base file (this object) do not exist
- Throws:
FileSystemException
- if an error occurs.
-
findFiles
public void findFiles(FileSelector selector, boolean depthwise, java.util.List<FileObject> selected) throws FileSystemException
Traverses the descendants of this file, and builds a list of selected files.- Specified by:
findFiles
in interfaceFileObject
- Parameters:
selector
- The FileSelector.depthwise
- if true files are added after their descendants, before otherwise.selected
- A List of the located FileObjects.- Throws:
FileSystemException
- if an error occurs.
-
getAbstractFileSystem
protected AFS getAbstractFileSystem()
Returns the file system this file belongs to.- Returns:
- The FileSystem this file is associated with.
-
getChild
public FileObject getChild(java.lang.String name) throws FileSystemException
Returns a child of this file.- Specified by:
getChild
in interfaceFileObject
- Parameters:
name
- The name of the child to locate.- Returns:
- The FileObject for the file or null if the child does not exist.
- Throws:
FileSystemException
- if an error occurs.
-
getChildren
public FileObject[] getChildren() throws FileSystemException
Returns the children of the file.- Specified by:
getChildren
in interfaceFileObject
- Returns:
- an array of FileObjects, one per child.
- Throws:
FileSystemException
- if an error occurs.
-
getContent
public FileContent getContent() throws FileSystemException
Returns the file's content.- Specified by:
getContent
in interfaceFileObject
- Returns:
- the FileContent for this FileObject.
- Throws:
FileSystemException
- if an error occurs.
-
getFileContentInfoFactory
protected FileContentInfoFactory getFileContentInfoFactory()
Creates the FileContentInfo factory.- Returns:
- The FileContentInfoFactory.
-
getFileOperations
public FileOperations getFileOperations() throws FileSystemException
- Specified by:
getFileOperations
in interfaceFileObject
- Returns:
- FileOperations interface that provides access to the operations API.
- Throws:
FileSystemException
- if an error occurs.
-
getFileSystem
public FileSystem getFileSystem()
Returns the file system this file belongs to.- Specified by:
getFileSystem
in interfaceFileObject
- Returns:
- The FileSystem this file is associated with.
-
getInputStream
public java.io.InputStream getInputStream() throws FileSystemException
Returns an input stream to use to read the content of the file.- Returns:
- The InputStream to access this file's content.
- Throws:
FileSystemException
- if an error occurs.
-
getName
public FileName getName()
Returns the name of the file.- Specified by:
getName
in interfaceFileObject
- Returns:
- The FileName, never
null
.
-
getPublicURIString
public java.lang.String getPublicURIString()
Returns the receiver as a URI String for public display, like, without a password.- Specified by:
getPublicURIString
in interfaceFileObject
- Returns:
- A URI String without a password, never
null
.
-
getOutputStream
public java.io.OutputStream getOutputStream() throws FileSystemException
Prepares this file for writing. Makes sure it is either a file, or its parent folder exists. Returns an output stream to use to write the content of the file to.- Returns:
- An OutputStream where the new contents of the file can be written.
- Throws:
FileSystemException
- if an error occurs.
-
getOutputStream
public java.io.OutputStream getOutputStream(boolean bAppend) throws FileSystemException
Prepares this file for writing. Makes sure it is either a file, or its parent folder exists. Returns an output stream to use to write the content of the file to.- Parameters:
bAppend
- true when append to the file.
Note: If the underlying filesystem does not support appending, a FileSystemException is thrown.- Returns:
- An OutputStream where the new contents of the file can be written.
- Throws:
FileSystemException
- if an error occurs; for example:
bAppend is true, and the underlying FileSystem does not support it
-
getParent
public FileObject getParent() throws FileSystemException
Returns the parent of the file.- Specified by:
getParent
in interfaceFileObject
- Returns:
- the parent FileObject.
- Throws:
FileSystemException
- if an error occurs.
-
getRandomAccessContent
public RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
Returns an input/output stream to use to read and write the content of the file in and random manner.- Parameters:
mode
- The RandomAccessMode.- Returns:
- The RandomAccessContent.
- Throws:
FileSystemException
- if an error occurs.
-
getType
public FileType getType() throws FileSystemException
Returns the file's type.- Specified by:
getType
in interfaceFileObject
- Returns:
- The FileType.
- Throws:
FileSystemException
- if an error occurs.
-
getURL
public java.net.URL getURL() throws FileSystemException
Returns a URL representation of the file.- Specified by:
getURL
in interfaceFileObject
- Returns:
- The URL representation of the file.
- Throws:
FileSystemException
- if an error occurs.
-
handleChanged
protected void handleChanged() throws java.lang.Exception
Called when this file is changed.This will only happen if you monitor the file using
FileMonitor
.- Throws:
java.lang.Exception
- if an error occurs.
-
handleCreate
protected void handleCreate(FileType newType) throws java.lang.Exception
Called when this file is created. Updates cached info and notifies the parent and file system.- Parameters:
newType
- The type of the file.- Throws:
java.lang.Exception
- if an error occurs.
-
handleDelete
protected void handleDelete() throws java.lang.Exception
Called when this file is deleted. Updates cached info and notifies subclasses, parent and file system.- Throws:
java.lang.Exception
- if an error occurs.
-
holdObject
public void holdObject(java.lang.Object strongRef)
This method is meant to add an object where this object holds a strong reference then. E.g. a archive-filesystem creates a list of all children and they shouldn't get garbage collected until the container is garbage collected- Parameters:
strongRef
- The Object to add.
-
injectType
protected void injectType(FileType fileType)
-
isAttached
public boolean isAttached()
Check if the internal state is "attached".- Specified by:
isAttached
in interfaceFileObject
- Returns:
- true if this is the case
-
isContentOpen
public boolean isContentOpen()
Check if the content stream is open.- Specified by:
isContentOpen
in interfaceFileObject
- Returns:
- true if this is the case
-
isExecutable
public boolean isExecutable() throws FileSystemException
Determines if this file is executable.- Specified by:
isExecutable
in interfaceFileObject
- Returns:
true
if this file is executable,false
if not.- Throws:
FileSystemException
- On error determining if this file exists.
-
isFile
public boolean isFile() throws FileSystemException
Checks if this file is a regular file by using its file type.- Specified by:
isFile
in interfaceFileObject
- Returns:
- true if this file is a regular file.
- Throws:
FileSystemException
- if an error occurs.- See Also:
getType()
,FileType.FILE
-
isFolder
public boolean isFolder() throws FileSystemException
Checks if this file is a folder by using its file type.- Specified by:
isFolder
in interfaceFileObject
- Returns:
- true if this file is a regular file.
- Throws:
FileSystemException
- if an error occurs.- See Also:
getType()
,FileType.FOLDER
-
isHidden
public boolean isHidden() throws FileSystemException
Determines if this file can be read.- Specified by:
isHidden
in interfaceFileObject
- Returns:
- true if the file is a hidden file, false otherwise.
- Throws:
FileSystemException
- if an error occurs.
-
isReadable
public boolean isReadable() throws FileSystemException
Determines if this file can be read.- Specified by:
isReadable
in interfaceFileObject
- Returns:
- true if the file can be read, false otherwise.
- Throws:
FileSystemException
- if an error occurs.
-
isSameFile
protected boolean isSameFile(FileObject destFile) throws FileSystemException
Checks if this fileObject is the same file asdestFile
just with a different name. E.g. for case insensitive filesystems like windows.- Parameters:
destFile
- The file to compare to.- Returns:
- true if the FileObjects are the same.
- Throws:
FileSystemException
- if an error occurs.
-
isWriteable
public boolean isWriteable() throws FileSystemException
Determines if this file can be written to.- Specified by:
isWriteable
in interfaceFileObject
- Returns:
- true if the file can be written to, false otherwise.
- Throws:
FileSystemException
- if an error occurs.
-
iterator
public java.util.Iterator<FileObject> iterator()
Returns an iterator over a set of all FileObject in this file object.- Specified by:
iterator
in interfacejava.lang.Iterable<AFS extends AbstractFileSystem>
- Returns:
- an Iterator.
-
listFiles
public java.util.List<FileObject> listFiles(FileSelector selector) throws FileSystemException
Lists the set of matching descendants of this file, in depthwise order.- Parameters:
selector
- The FileSelector.- Returns:
- list of files or null if the base file (this object) do not exist or the
selector
is null - Throws:
FileSystemException
- if an error occurs.
-
moveTo
public void moveTo(FileObject destFile) throws FileSystemException
Moves (rename) the file to another one.- Specified by:
moveTo
in interfaceFileObject
- Parameters:
destFile
- The target FileObject.- Throws:
FileSystemException
- if an error occurs.
-
notifyAllStreamsClosed
protected void notifyAllStreamsClosed()
will be called after this file-object closed all its streams.
-
onChange
protected void onChange() throws java.lang.Exception
Called when the type or content of this file changes.This implementation does nothing.
- Throws:
java.lang.Exception
- if an error occurs.
-
onChildrenChanged
protected void onChildrenChanged(FileName child, FileType newType) throws java.lang.Exception
Called when the children of this file change. Allows subclasses to refresh any cached information about the children of this file.This implementation does nothing.
- Parameters:
child
- The name of the child that changed.newType
- The type of the file.- Throws:
java.lang.Exception
- if an error occurs.
-
refresh
public void refresh() throws FileSystemException
This will prepare the fileObject to get resynchronized with the underlying filesystem if required.- Specified by:
refresh
in interfaceFileObject
- Throws:
FileSystemException
- if an error occurs.
-
resolveFile
public FileObject resolveFile(java.lang.String path) throws FileSystemException
Finds a file, relative to this file.- Specified by:
resolveFile
in interfaceFileObject
- Parameters:
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.- Returns:
- The FileObject.
- Throws:
FileSystemException
- if an error occurs.
-
resolveFile
public FileObject resolveFile(java.lang.String name, NameScope scope) throws FileSystemException
Returns a child by name.- Specified by:
resolveFile
in interfaceFileObject
- Parameters:
name
- The name of the child to locate.scope
- the NameScope.- Returns:
- The FileObject for the file or null if the child does not exist.
- Throws:
FileSystemException
- if an error occurs.
-
setExecutable
public boolean setExecutable(boolean readable, boolean ownerOnly) throws FileSystemException
Description copied from interface:FileObject
Sets the owner's (or everybody's) write permission.- Specified by:
setExecutable
in interfaceFileObject
- Parameters:
readable
- True to allow read access, false to disallow.ownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded.
- Throws:
FileSystemException
- On error determining if this file exists.
-
setReadable
public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
Description copied from interface:FileObject
Sets the owner's (or everybody's) read permission.- Specified by:
setReadable
in interfaceFileObject
- Parameters:
readable
- True to allow read access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
FileSystemException
- On error determining if this file exists.
-
setWritable
public boolean setWritable(boolean readable, boolean ownerOnly) throws FileSystemException
Description copied from interface:FileObject
Sets the owner's (or everybody's) write permission.- Specified by:
setWritable
in interfaceFileObject
- Parameters:
readable
- True to allow read access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
FileSystemException
- On error determining if this file exists.
-
toString
public java.lang.String toString()
Returns the URI as a String.- Overrides:
toString
in classjava.lang.Object
- Returns:
- Returns the URI as a String.
-
-