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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLocalFile(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 voiddoAttach()Attaches this file object to its file resource.protected voiddoCreateFolder()Creates this folder.protected voiddoDelete()Deletes this file, and all children.protected longdoGetContentSize()Returns the size of the file content (in bytes).protected java.io.InputStreamdoGetInputStream()Creates an input stream to read the content from.protected longdoGetLastModifiedTime()Gets the last modified time of this file.protected java.io.OutputStreamdoGetOutputStream(boolean bAppend)Creates an output stream to write the file content to.protected RandomAccessContentdoGetRandomAccessContent(RandomAccessMode mode)Creates access to the file for random i/o.protected FileTypedoGetType()Returns the file's type.protected booleandoIsExecutable()Determines if this file is hidden.protected booleandoIsHidden()Determines if this file is hidden.protected booleandoIsReadable()Determines if this file can be read.protected booleandoIsSameFile(FileObject destFile)Checks if this fileObject is the same file asdestFilejust with a different name.protected booleandoIsWriteable()Determines if this file can be written to.protected java.lang.String[]doListChildren()Returns the children of the file.protected voiddoRename(FileObject newFile)rename this fileprotected booleandoSetExecutable(boolean executable, boolean ownerOnly)Make the file executable.protected booleandoSetLastModifiedTime(long modtime)Sets the last modified time of this file.protected booleandoSetReadable(boolean readable, boolean ownerOnly)Make the file or folder readable.protected booleandoSetWritable(boolean writable, boolean ownerOnly)Make the file or folder writeable.protected java.io.FilegetLocalFile()Returns the local file that this file object represents.java.lang.StringtoString()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, doListChildrenResolved, doRemoveAttribute, doSetAttribute, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getChildren, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getName, getOutputStream, getOutputStream, getParent, getPublicURIString, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, refresh, resolveFile, resolveFile, setExecutable, setReadable, setWritable
-
-
-
-
Constructor Detail
-
LocalFile
protected LocalFile(LocalFileSystem fileSystem, java.lang.String rootFile, AbstractFileName name) throws FileSystemException
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.- Throws:
FileSystemException- if an error occurs.
-
-
Method Detail
-
getLocalFile
protected java.io.File getLocalFile()
Returns the local file that this file object represents.- Returns:
- the local file that this file object represents.
-
doAttach
protected void doAttach() throws java.lang.Exception
Attaches this file object to its file resource.- Overrides:
doAttachin classAbstractFileObject<LocalFileSystem>- Throws:
java.lang.Exception- if an error occurs.
-
doGetType
protected FileType doGetType() throws java.lang.Exception
Returns the file's type.- Specified by:
doGetTypein classAbstractFileObject<LocalFileSystem>- Returns:
- the type of the file.
- Throws:
java.lang.Exception- if an error occurs.
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Returns the children of the file.- Specified by:
doListChildrenin 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.
-
doDelete
protected void doDelete() throws java.lang.Exception
Deletes this file, and all children.- Overrides:
doDeletein classAbstractFileObject<LocalFileSystem>- Throws:
java.lang.Exception- if an error occurs.
-
doRename
protected void doRename(FileObject newFile) throws java.lang.Exception
rename this file- Overrides:
doRenamein classAbstractFileObject<LocalFileSystem>- Parameters:
newFile- A FileObject with the new file name.- Throws:
java.lang.Exception- if an error occurs.
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Creates this folder.- Overrides:
doCreateFolderin classAbstractFileObject<LocalFileSystem>- Throws:
java.lang.Exception- if an error occurs.
-
doIsWriteable
protected boolean doIsWriteable() throws FileSystemException
Determines if this file can be written to.- Overrides:
doIsWriteablein classAbstractFileObject<LocalFileSystem>- Returns:
- true if the file is writable.
- Throws:
FileSystemException
-
doSetWritable
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObjectMake the file or folder writeable.Only called if
AbstractFileObject.doGetType()does not returnFileType.IMAGINARY.- Overrides:
doSetWritablein 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)
-
doIsExecutable
protected boolean doIsExecutable()
Determines if this file is hidden.- Overrides:
doIsExecutablein classAbstractFileObject<LocalFileSystem>- Returns:
- true if the file is executable, false otherwise.
-
doIsHidden
protected boolean doIsHidden()
Determines if this file is hidden.- Overrides:
doIsHiddenin 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:
doIsReadablein classAbstractFileObject<LocalFileSystem>- Returns:
- true if the file is readable, false otherwise.
- Throws:
FileSystemException
-
doSetReadable
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObjectMake the file or folder readable.Only called if
AbstractFileObject.doGetType()does not returnFileType.IMAGINARY.This implementation returns false.
- Overrides:
doSetReadablein 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)
-
doSetExecutable
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObjectMake the file executable.Only called if
AbstractFileObject.doGetType()does not returnFileType.IMAGINARY.This implementation returns false.
- Overrides:
doSetExecutablein 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)
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws FileSystemException
Gets the last modified time of this file.- Overrides:
doGetLastModifiedTimein classAbstractFileObject<LocalFileSystem>- Returns:
- The last modification time.
- Throws:
FileSystemException
-
doSetLastModifiedTime
protected boolean doSetLastModifiedTime(long modtime) throws FileSystemException
Sets the last modified time of this file.- Overrides:
doSetLastModifiedTimein classAbstractFileObject<LocalFileSystem>- Parameters:
modtime- The last modification time.- Returns:
- true if the time was set.
- Throws:
FileSystemException- Since:
- 2.0
-
doGetInputStream
protected java.io.InputStream doGetInputStream() throws java.lang.Exception
Creates an input stream to read the content from.- Specified by:
doGetInputStreamin classAbstractFileObject<LocalFileSystem>- Returns:
- An InputStream to read the file content.
- 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.- Overrides:
doGetOutputStreamin 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.
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Returns the size of the file content (in bytes).- Specified by:
doGetContentSizein classAbstractFileObject<LocalFileSystem>- Returns:
- The size of the file in bytes.
- Throws:
java.lang.Exception- if an error occurs.
-
doGetRandomAccessContent
protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode) throws java.lang.Exception
Description copied from class:AbstractFileObjectCreates 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:
doGetRandomAccessContentin classAbstractFileObject<LocalFileSystem>- Parameters:
mode- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception- if an error occurs.
-
doIsSameFile
protected boolean doIsSameFile(FileObject destFile) throws FileSystemException
Description copied from class:AbstractFileObjectChecks if this fileObject is the same file asdestFilejust with a different name. E.g. for case insensitive filesystems like windows.- Overrides:
doIsSameFilein classAbstractFileObject<LocalFileSystem>- Parameters:
destFile- The file to compare to.- Returns:
- true if the FileObjects are the same.
- Throws:
FileSystemException- if an error occurs.
-
toString
public java.lang.String toString()
Returns the URI of the file.- Overrides:
toStringin classAbstractFileObject<LocalFileSystem>- Returns:
- The URI of the file.
-
-