Class LocalFile
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileObject<LocalFileSystem>
-
- org.apache.commons.vfs2.provider.local.LocalFile
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Comparable<FileObject>
,java.lang.Iterable<FileObject>
,FileObject
public class LocalFile extends AbstractFileObject<LocalFileSystem>
A file object implementation which uses direct file access.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
file
private java.lang.String
rootFile
-
Fields inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
DEFAULT_BUFFER_SIZE
-
Fields inherited from interface org.apache.commons.vfs2.FileObject
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LocalFile(LocalFileSystem fileSystem, java.lang.String rootFile, AbstractFileName name)
Creates a non-root file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doAttach()
Attaches this file object to its file resource.protected void
doCreateFolder()
Creates this folder.protected void
doDelete()
Deletes this file, and all children.protected long
doGetContentSize()
Returns the size of the file content (in bytes).protected java.io.InputStream
doGetInputStream(int bufferSize)
Creates an input stream to read the content from.protected long
doGetLastModifiedTime()
Gets 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 FileType
doGetType()
Returns the file's type.protected boolean
doIsExecutable()
Determines if this file is hidden.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
doIsSymbolicLink()
Determines if this file is a symbolic link.protected boolean
doIsWriteable()
Determines if this file can be written to.protected java.lang.String[]
doListChildren()
Returns the children of the file.protected void
doRename(FileObject newFile)
rename this fileprotected 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 java.io.File
getLocalFile()
Gets the local file that this file object represents.java.lang.String
toString()
Returns the URI of the file.-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
canRenameTo, childrenChanged, close, compareTo, copyFrom, createFile, createFolder, delete, delete, deleteAll, doCreateFileContent, doDetach, doGetAttributes, doGetCertificates, doGetInputStream, doListChildrenResolved, doRemoveAttribute, doSetAttribute, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getChildren, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getInputStream, getName, getOutputStream, getOutputStream, getParent, getPublicURIString, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isSymbolicLink, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, refresh, resolveFile, resolveFile, setExecutable, setReadable, setWritable
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.vfs2.FileObject
getPath, getURI
-
-
-
-
Constructor Detail
-
LocalFile
protected LocalFile(LocalFileSystem fileSystem, java.lang.String rootFile, AbstractFileName name)
Creates a non-root file.- Parameters:
fileSystem
- the file system this file belongs to.rootFile
- the root file for the file system.name
- the file name on this file system.
-
-
Method Detail
-
doAttach
protected void doAttach() throws java.lang.Exception
Attaches this file object to its file resource.- Overrides:
doAttach
in classAbstractFileObject<LocalFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Creates this folder.- Overrides:
doCreateFolder
in classAbstractFileObject<LocalFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doDelete
protected void doDelete() throws java.lang.Exception
Deletes this file, and all children.- Overrides:
doDelete
in classAbstractFileObject<LocalFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Returns the size of the file content (in bytes).- Specified by:
doGetContentSize
in classAbstractFileObject<LocalFileSystem>
- Returns:
- The size of the file in bytes.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetInputStream
protected java.io.InputStream doGetInputStream(int bufferSize) throws java.lang.Exception
Creates an input stream to read the content from.- Overrides:
doGetInputStream
in classAbstractFileObject<LocalFileSystem>
- Parameters:
bufferSize
- Buffer size hint.- Returns:
- An InputStream to read the file content.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws FileSystemException
Gets the last modified time of this file.- Overrides:
doGetLastModifiedTime
in classAbstractFileObject<LocalFileSystem>
- Returns:
- The last modification time.
- Throws:
FileSystemException
-
doGetOutputStream
protected java.io.OutputStream doGetOutputStream(boolean bAppend) throws java.lang.Exception
Creates an output stream to write the file content to.- Overrides:
doGetOutputStream
in classAbstractFileObject<LocalFileSystem>
- 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
Description copied from class:AbstractFileObject
Creates access to the file for random i/o. Is only called ifAbstractFileObject.doGetType()
returnsFileType.FILE
.It is guaranteed that there are no open output streams for this file when this method is called.
- Overrides:
doGetRandomAccessContent
in classAbstractFileObject<LocalFileSystem>
- Parameters:
mode
- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetType
protected FileType doGetType()
Returns the file's type.- Specified by:
doGetType
in classAbstractFileObject<LocalFileSystem>
- Returns:
- the type of the file.
-
doIsExecutable
protected boolean doIsExecutable()
Determines if this file is hidden.- Overrides:
doIsExecutable
in classAbstractFileObject<LocalFileSystem>
- Returns:
- true if the file is executable, false otherwise.
-
doIsHidden
protected boolean doIsHidden()
Determines if this file is hidden.- Overrides:
doIsHidden
in classAbstractFileObject<LocalFileSystem>
- Returns:
- true if the file is hidden, false otherwise.
-
doIsReadable
protected boolean doIsReadable() throws FileSystemException
Determines if this file can be read.- Overrides:
doIsReadable
in classAbstractFileObject<LocalFileSystem>
- Returns:
- true if the file is readable, false otherwise.
- Throws:
FileSystemException
-
doIsSameFile
protected boolean doIsSameFile(FileObject destFile) throws FileSystemException
Description copied from class:AbstractFileObject
Checks if this fileObject is the same file asdestFile
just with a different name. E.g. for case insensitive file systems like windows.- Overrides:
doIsSameFile
in classAbstractFileObject<LocalFileSystem>
- Parameters:
destFile
- The file to compare to.- Returns:
- true if the FileObjects are the same.
- Throws:
FileSystemException
- if an error occurs.
-
doIsSymbolicLink
protected boolean doIsSymbolicLink() throws FileSystemException
Determines if this file is a symbolic link.- Overrides:
doIsSymbolicLink
in classAbstractFileObject<LocalFileSystem>
- Returns:
- true if the file is readable, false otherwise.
- Throws:
FileSystemException
- Since:
- 2.4
-
doIsWriteable
protected boolean doIsWriteable() throws FileSystemException
Determines if this file can be written to.- Overrides:
doIsWriteable
in classAbstractFileObject<LocalFileSystem>
- Returns:
- true if the file is writable.
- Throws:
FileSystemException
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Returns the children of the file.- Specified by:
doListChildren
in classAbstractFileObject<LocalFileSystem>
- 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.
-
doRename
protected void doRename(FileObject newFile) throws java.lang.Exception
rename this file- Overrides:
doRename
in classAbstractFileObject<LocalFileSystem>
- Parameters:
newFile
- A FileObject with the new file name.- Throws:
java.lang.Exception
- if an error occurs.
-
doSetExecutable
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObject
Make the file executable.Only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation returns false.
- Overrides:
doSetExecutable
in classAbstractFileObject<LocalFileSystem>
- 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.- See Also:
AbstractFileObject.setExecutable(boolean, boolean)
-
doSetLastModifiedTime
protected boolean doSetLastModifiedTime(long modtime) throws FileSystemException
Sets the last modified time of this file.- Overrides:
doSetLastModifiedTime
in classAbstractFileObject<LocalFileSystem>
- Parameters:
modtime
- The last modification time.- Returns:
- true if the time was set.
- Throws:
FileSystemException
- Since:
- 2.0
-
doSetReadable
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObject
Make the file or folder readable.Only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation returns false.
- Overrides:
doSetReadable
in classAbstractFileObject<LocalFileSystem>
- 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.- See Also:
AbstractFileObject.setReadable(boolean, boolean)
-
doSetWritable
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObject
Make the file or folder writable.Only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.- Overrides:
doSetWritable
in classAbstractFileObject<LocalFileSystem>
- 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.- See Also:
AbstractFileObject.setWritable(boolean, boolean)
-
getLocalFile
protected java.io.File getLocalFile()
Gets the local file that this file object represents.- Returns:
- the local file that this file object represents.
-
toString
public java.lang.String toString()
Returns the URI of the file.- Overrides:
toString
in classAbstractFileObject<LocalFileSystem>
- Returns:
- The URI of the file.
-
-