AFS
- An AbstractFileSystem subclasspublic abstract class AbstractFileObject<AFS extends AbstractFileSystem> extends Object implements FileObject
TODO - Check caps in methods like getChildren(), etc, and give better error messages (eg 'this file type does not support listing children', vs 'this is not a folder')
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE
Same as
BufferedInputStream . |
EMPTY_ARRAY
Modifier | Constructor and Description |
---|---|
protected |
AbstractFileObject(AbstractFileName name,
AFS fileSystem) |
Modifier and Type | Method and Description |
---|---|
boolean |
canRenameTo(FileObject newfile)
Queries the object if a simple rename to the file name 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.
|
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 the
selector . |
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 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 InputStream |
doGetInputStream()
Creates an input stream to read the file content from.
|
protected InputStream |
doGetInputStream(int bufferSize)
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 |
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 as
destFile just with a different name. |
protected boolean |
doIsSymbolicLink()
Determines if this file is a symbolic link.
|
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 |
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 writable.
|
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,
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(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.
|
InputStream |
getInputStream()
Returns an input stream to use to read the content of the file.
|
InputStream |
getInputStream(int bufferSize)
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.
|
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.
|
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 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 as
destFile just with a different name. |
boolean |
isSymbolicLink()
Determines if this file can be read.
|
boolean |
isWriteable()
Determines if this file can be written to.
|
Iterator<FileObject> |
iterator()
Returns an iterator over a set of all FileObject in this file object.
|
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()
Clled 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 file system if required.
|
FileObject |
resolveFile(String path)
Finds a file, relative to this file.
|
FileObject |
resolveFile(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.
|
String |
toString()
Returns the URI as a String.
|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getPath, getURI
forEach, spliterator
public static final int DEFAULT_BUFFER_SIZE
BufferedInputStream
.protected AbstractFileObject(AbstractFileName name, AFS fileSystem)
name
- the file name - muse be an instance of AbstractFileName
fileSystem
- the file systemClassCastException
- if name
is not an instance of AbstractFileName
public boolean canRenameTo(FileObject newfile)
newfile
is possible.canRenameTo
in interface FileObject
newfile
- the new file nameprotected 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 close() throws FileSystemException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface FileObject
FileSystemException
- if an error occurs.FileContent.close()
public int compareTo(FileObject file)
compareTo
in interface Comparable<FileObject>
file
- the object to compare.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 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 boolean delete() throws FileSystemException
TODO - This will not fail if this is a non-empty folder.
delete
in interface FileObject
FileSystemException
- if an error occurs.public int delete(FileSelector selector) throws FileSystemException
selector
.delete
in interface FileObject
selector
- The FileSelector.FileSystemException
- if an error occurs.public int deleteAll() throws FileSystemException
delete(Selectors.SELECT_ALL)
deleteAll
in interface FileObject
FileSystemException
- if an error occurs.delete(FileSelector)
,
Selectors.SELECT_ALL
protected void doAttach() throws Exception
This method is called before any of the doBlah() or onBlah() methods. Sub-classes can use this method to perform lazy initialization.
This implementation does nothing.
Exception
- if an error occurs.protected FileContent doCreateFileContent() throws FileSystemException
FileSystemException
- if an error occurs.protected void doCreateFolder() throws Exception
doGetType()
returns FileType.IMAGINARY
.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 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 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 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 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 InputStream doGetInputStream(int bufferSize) 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.
bufferSize
- Buffer size hint.Exception
- if an error occurs.protected long doGetLastModifiedTime() throws Exception
doGetType()
does not return
This implementation throws an exception.
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.
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.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 abstract FileType doGetType() throws Exception
Exception
- if an error occurs.protected boolean doIsExecutable() throws Exception
doGetType()
does not return
FileType.IMAGINARY
.
This implementation always returns false.
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 doIsSameFile(FileObject destFile) throws FileSystemException
destFile
just with a different name. E.g. for case
insensitive file systems like windows.destFile
- The file to compare to.FileSystemException
- if an error occurs.protected boolean doIsSymbolicLink() throws Exception
doGetType()
does not return
FileType.IMAGINARY
.
This implementation always returns false.
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
Is only called if doGetType()
returns FileType.FOLDER
.
The return value of this method is cached, so the implementation can be expensive.
Other than doListChildren
you could return FileObject's to e.g. reinitialize the type of the file.
(Introduced for Webdav: "permission denied on resource" during getType())
Exception
- if an error occurs.protected void doRemoveAttribute(String attrName) throws Exception
Is only called if 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 void doRename(FileObject newFile) throws Exception
Is only called when:
doIsWriteable()
returns true.This implementation throws an exception.
newFile
- A FileObject with the new file name.Exception
- if an error occurs.protected void doSetAttribute(String attrName, Object value) throws Exception
Is only called if 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 boolean doSetExecutable(boolean executable, boolean ownerOnly) throws Exception
Only called if doGetType()
does not return FileType.IMAGINARY
.
This implementation returns false.
executable
- True to allow access, false to disallow.ownerOnly
- If true
, the permission applies only to the owner; otherwise, it applies to everybody.Exception
- Any Exception thrown is wrapped in FileSystemException.setExecutable(boolean, boolean)
protected boolean doSetLastModifiedTime(long modtime) throws Exception
Is only called if doGetType()
does not return FileType.IMAGINARY
.
This implementation throws an exception.
modtime
- The last modification time.Exception
- Any Exception thrown is wrapped in FileSystemException.protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws Exception
Only called if doGetType()
does not return FileType.IMAGINARY
.
This implementation returns false.
readable
- True to allow access, false to disallowownerOnly
- If true
, the permission applies only to the owner; otherwise, it applies to everybody.Exception
- Any Exception thrown is wrapped in FileSystemException.setReadable(boolean, boolean)
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws Exception
Only called if doGetType()
does not return FileType.IMAGINARY
.
writable
- True to allow access, false to disallowownerOnly
- If true
, the permission applies only to the owner; otherwise, it applies to everybody.Exception
- Any Exception thrown is wrapped in FileSystemException.setWritable(boolean, boolean)
protected void endOutput() throws Exception
Exception
- if an error occurs.public boolean exists() throws FileSystemException
exists
in interface FileObject
FileSystemException
- if an error occurs.protected void finalize() throws Throwable
public FileObject[] findFiles(FileSelector selector) throws FileSystemException
findFiles
in interface FileObject
selector
- The FileSelector.FileSystemException
- 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.protected AFS getAbstractFileSystem()
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[] getChildren() throws FileSystemException
getChildren
in interface FileObject
FileSystemException
- if an error occurs.public FileContent getContent() throws FileSystemException
getContent
in interface FileObject
FileSystemException
- if an error occurs.protected FileContentInfoFactory getFileContentInfoFactory()
public FileOperations getFileOperations() throws FileSystemException
getFileOperations
in interface FileObject
FileSystemException
- if an error occurs.public FileSystem getFileSystem()
getFileSystem
in interface FileObject
public InputStream getInputStream() throws FileSystemException
FileSystemException
- if an error occurs.public InputStream getInputStream(int bufferSize) throws FileSystemException
bufferSize
- buffer size hint.FileSystemException
- if an error occurs.public FileName getName()
getName
in interface FileObject
null
.public OutputStream getOutputStream() throws FileSystemException
FileSystemException
- if an error occurs.public OutputStream getOutputStream(boolean bAppend) throws FileSystemException
bAppend
- true when append to the file.
Note: If the underlying file system does not support appending, a FileSystemException is thrown.FileSystemException
- if an error occurs; for example:
bAppend is true, and the underlying FileSystem does not support itpublic FileObject getParent() throws FileSystemException
getParent
in interface FileObject
FileSystemException
- if an error occurs.public String getPublicURIString()
getPublicURIString
in interface FileObject
null
.public RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
mode
- The RandomAccessMode.FileSystemException
- if an error occurs.public FileType getType() throws FileSystemException
getType
in interface FileObject
FileSystemException
- if an error occurs.public URL getURL() throws FileSystemException
getURL
in interface FileObject
FileSystemException
- if an error occurs.protected void handleChanged() throws Exception
This will only happen if you monitor the file using FileMonitor
.
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.public void holdObject(Object strongRef)
strongRef
- The Object to add.protected void injectType(FileType fileType)
public boolean isAttached()
isAttached
in interface FileObject
public boolean isContentOpen()
isContentOpen
in interface FileObject
public boolean isExecutable() throws FileSystemException
isExecutable
in interface FileObject
true
if this file is executable, false
if not.FileSystemException
- On error determining if this file exists.public boolean isFile() throws FileSystemException
isFile
in interface FileObject
FileSystemException
- if an error occurs.getType()
,
FileType.FILE
public boolean isFolder() throws FileSystemException
isFolder
in interface FileObject
FileSystemException
- if an error occurs.getType()
,
FileType.FOLDER
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.protected boolean isSameFile(FileObject destFile) throws FileSystemException
destFile
just with a different name. E.g. for case
insensitive file systems like windows.destFile
- The file to compare to.FileSystemException
- if an error occurs.public boolean isSymbolicLink() throws FileSystemException
isSymbolicLink
in interface FileObject
FileSystemException
- if an error occurs.public boolean isWriteable() throws FileSystemException
isWriteable
in interface FileObject
FileSystemException
- if an error occurs.public Iterator<FileObject> iterator()
iterator
in interface Iterable<FileObject>
public List<FileObject> listFiles(FileSelector selector) throws FileSystemException
selector
- The FileSelector.selector
is nullFileSystemException
- 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 void notifyAllStreamsClosed()
protected void onChange() throws Exception
This implementation does nothing.
Exception
- if an error occurs.protected void onChildrenChanged(FileName child, FileType newType) throws Exception
This implementation does nothing.
child
- The name of the child that changed.newType
- The type of the file.Exception
- if an error occurs.public void refresh() throws FileSystemException
refresh
in interface FileObject
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 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 boolean setExecutable(boolean readable, boolean ownerOnly) throws FileSystemException
FileObject
setExecutable
in interface FileObject
readable
- True to allow read access, false to disallow.ownerOnly
- If true
, the permission applies only to the owner; otherwise, it applies to everybody.FileSystemException
- On error determining if this file exists.public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
FileObject
setReadable
in interface FileObject
readable
- True to allow read access, false to disallowownerOnly
- If true
, the permission applies only to the owner; otherwise, it applies to everybody.FileSystemException
- On error determining if this file exists.public boolean setWritable(boolean readable, boolean ownerOnly) throws FileSystemException
FileObject
setWritable
in interface FileObject
readable
- True to allow read access, false to disallowownerOnly
- If true
, the permission applies only to the owner; otherwise, it applies to everybody.FileSystemException
- On error determining if this file exists.Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.