Class RamFileObject
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileObject<RamFileSystem>
-
- org.apache.commons.vfs2.provider.ram.RamFileObject
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Comparable<FileObject>
,java.lang.Iterable<FileObject>
,FileObject
public class RamFileObject extends AbstractFileObject<RamFileSystem>
A RAM File contains a single RAM FileData instance, it provides methods to access the data by implementing FileObject interface.
-
-
Field Summary
Fields Modifier and Type Field Description private RamFileData
data
RAM File Object Data.-
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
RamFileObject(AbstractFileName name, RamFileSystem fs)
-
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 file as a folder.protected void
doDelete()
Deletes the file.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 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 FileType
doGetType()
Determines the type of this file.protected java.lang.String[]
doListChildren()
Lists the children of this file.protected void
doRename(FileObject newFile)
Renames the file.protected boolean
doSetLastModifiedTime(long modtime)
Sets the last modified time of this file.protected void
endOutput()
Called when the output stream for this file is closed.(package private) RamFileData
getData()
protected void
injectType(FileType fileType)
(package private) void
resize(long newSize)
private void
save()
(package private) void
setData(RamFileData data)
(package private) int
size()
-
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, doIsExecutable, doIsHidden, doIsReadable, doIsSameFile, doIsSymbolicLink, doIsWriteable, doListChildrenResolved, doRemoveAttribute, doSetAttribute, doSetExecutable, doSetReadable, doSetWritable, 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, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isSymbolicLink, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, refresh, resolveFile, resolveFile, setExecutable, setReadable, setWritable, toString
-
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
-
-
-
-
Field Detail
-
data
private RamFileData data
RAM File Object Data.
-
-
Constructor Detail
-
RamFileObject
protected RamFileObject(AbstractFileName name, RamFileSystem fs)
- Parameters:
name
- The name of the file.fs
- The FileSystem.
-
-
Method Detail
-
save
private void save() throws FileSystemException
- Throws:
FileSystemException
-
doGetType
protected FileType doGetType() throws java.lang.Exception
Description copied from class:AbstractFileObject
Determines the type of this file. Must not return null. The return value of this method is cached, so the implementation can be expensive.- Specified by:
doGetType
in classAbstractFileObject<RamFileSystem>
- Returns:
- the type of the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Description copied from class:AbstractFileObject
Lists the children of this file. Is only called ifAbstractFileObject.doGetType()
returnsFileType.FOLDER
. The return value of this method is cached, so the implementation can be expensive.- Specified by:
doListChildren
in classAbstractFileObject<RamFileSystem>
- 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.
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Description copied from class:AbstractFileObject
Returns the size of the file content (in bytes). Is only called ifAbstractFileObject.doGetType()
returnsFileType.FILE
.- Specified by:
doGetContentSize
in classAbstractFileObject<RamFileSystem>
- 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
Description copied from class:AbstractFileObject
Creates an input stream to read the file content from. 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.
The returned stream does not have to be buffered.
- Overrides:
doGetInputStream
in classAbstractFileObject<RamFileSystem>
- Parameters:
bufferSize
- Buffer size hint.- 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
Description copied from class:AbstractFileObject
Creates an output stream to write the file content to. Is only called if:AbstractFileObject.doIsWriteable()
returns true.AbstractFileObject.doGetType()
returnsFileType.FILE
, orAbstractFileObject.doGetType()
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.
- Overrides:
doGetOutputStream
in classAbstractFileObject<RamFileSystem>
- 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.
-
doDelete
protected void doDelete() throws java.lang.Exception
Description copied from class:AbstractFileObject
Deletes the file. Is only called when:AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.AbstractFileObject.doIsWriteable()
returns true.- This file has no children, if a folder.
- Overrides:
doDelete
in classAbstractFileObject<RamFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws java.lang.Exception
Description copied from class:AbstractFileObject
Returns the last modified time of this file. Is only called ifAbstractFileObject.doGetType()
does not returnThis implementation throws an exception.
- Overrides:
doGetLastModifiedTime
in classAbstractFileObject<RamFileSystem>
- Returns:
- The last modification time.
- Throws:
java.lang.Exception
- if an error occurs.
-
doSetLastModifiedTime
protected boolean doSetLastModifiedTime(long modtime) throws java.lang.Exception
Description copied from class:AbstractFileObject
Sets the last modified time of this file.Is only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation throws an exception.
- Overrides:
doSetLastModifiedTime
in classAbstractFileObject<RamFileSystem>
- Parameters:
modtime
- The last modification time.- Returns:
- true if the time was set.
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- Since:
- 2.0
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Description copied from class:AbstractFileObject
Creates this file as a folder. Is only called when:AbstractFileObject.doGetType()
returnsFileType.IMAGINARY
.- The parent folder exists and is writable, or this file is the root of the file system.
- Overrides:
doCreateFolder
in classAbstractFileObject<RamFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doRename
protected void doRename(FileObject newFile) throws java.lang.Exception
Description copied from class:AbstractFileObject
Renames the file.Is only called when:
AbstractFileObject.doIsWriteable()
returns true.
This implementation throws an exception.
- Overrides:
doRename
in classAbstractFileObject<RamFileSystem>
- Parameters:
newFile
- A FileObject with the new file name.- 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<RamFileSystem>
- Parameters:
mode
- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception
- if an error occurs.
-
doAttach
protected void doAttach() throws java.lang.Exception
Description copied from class:AbstractFileObject
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 initialization.
This implementation does nothing.
- Overrides:
doAttach
in classAbstractFileObject<RamFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
getData
RamFileData getData()
- Returns:
- Returns the data.
-
setData
void setData(RamFileData data)
- Parameters:
data
- The data to set.
-
injectType
protected void injectType(FileType fileType)
- Overrides:
injectType
in classAbstractFileObject<RamFileSystem>
-
endOutput
protected void endOutput() throws java.lang.Exception
Description copied from class:AbstractFileObject
Called when the output stream for this file is closed.- Overrides:
endOutput
in classAbstractFileObject<RamFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
size
int size()
- Returns:
- Returns the size of the
RamFileData
.
-
resize
void resize(long newSize) throws java.io.IOException
- Parameters:
newSize
- The new buffer size.- Throws:
java.io.IOException
- if the new size exceeds the limit
-
-