|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.borland.primetime.vfs.Buffer
A Buffer is an in-memory representation of the information referred to by a Url, and as such may represent changes to a Url that have not yet been saved to permanent storage.
Url
Field Summary | |
static Buffer[] |
EMPTY_ARRAY
A convenient zero-length array of type Buffer[] |
static long |
MODIFIED_NEVER
Reported as the last modification time for resources that do not yet have an on-disk representation |
static int |
STATE_LOADING
When this bit is set in a state integer it means the buffer state is changing as a result of loading the buffer's contents from a VFS filesystem. |
static int |
STATE_MODIFIED
When this bit is set in a state integer it means the buffer's contents are different from the filesystem representation. |
static int |
STATE_READONLY
When this bit is set in a state integer it means the buffer's contents are marked read only. |
Constructor Summary | |
Buffer(Url url)
Initializes a new Buffer instance to represent the contents of a specified Url. |
Method Summary | |
void |
addBufferListener(BufferListener listener)
Adds a BufferListener to the list of listeners that receive buffer events from this buffer. |
void |
check()
The buffer's sourceLastModified property is compared with the
original Url's last modification to ensure that the in-memory
representation is up to date with changes that may have been made outside
the VFS. |
void |
fireBufferChanged(BufferUpdater updater)
Notifies all registered BufferListeners that the content of the buffer has been changed. |
void |
fireBufferLoaded()
Notifies all registered BufferListeners that the content of the buffer has been loaded. |
void |
fireBufferSaving()
Notifies all registered BufferListeners that the content of the buffer is about to be saved. |
void |
fireBufferStateChanged(int oldState,
int newState)
Notifies all registered BufferListeners that the state of the buffer has been changed. |
byte[] |
getBufferContent(Buffer buffer)
Reads the conents of the buffer's Url source and returns it as a byte array. |
byte[] |
getContent()
Returns the buffer's contents as an array of bytes. |
java.io.InputStream |
getInputStream()
Creates an InputStream to provide read-only access to the contents of the buffer as defined by getContent . |
long |
getLastModified()
Returns a timestamp representing the last time the buffer's contents were modified. |
static int |
getModifiedBufferCount()
Returns the count of all buffers managed by the VFS that are currently marked as modified. |
static Buffer[] |
getModifiedBuffers()
Returns a copy of the list of all buffers managed by the VFS that are currently marked as modified. |
java.io.OutputStream |
getOutputStream()
Creates an OutputStream to provide write access to the contents of the buffer. |
int |
getSize()
Reports the length of the buffer content in bytes. |
long |
getSourceLastModified()
A timestamp representing the last time the source of the buffer's contents had been modified at the time the buffer was read. |
Url |
getUrl()
Returns the Url that this buffer represents. |
boolean |
isLoading()
Determines if the buffer is in the midst of being loaded from permanent storage. |
boolean |
isModified()
Determines if the buffer has been changed since it was last loaded from or saved to permanent storage. |
boolean |
isReadOnly()
Reports whether the buffer is currently read only, a state that is typically kept in sync with the state of the source of the buffer by the virtual file system. |
void |
removeBufferListener(BufferListener listener)
Removes a BufferListener from the list of listeners that receive buffer events from this buffer. |
void |
revert()
Reads the conents of the buffer's Url source, marks the buffer unmodified, and sets the buffer's read-only state to match that of the source Url. |
void |
save()
|
void |
save(boolean useMultiLevelBackups)
Writes the contents of a buffer to its Url and marks the buffer unmodified. |
void |
setContent(BufferUpdater updater)
Sets the contents of the buffer in a lazy fasion using a BufferUpdater. |
void |
setContent(byte[] content)
Sets the buffer's contents as an array of bytes. |
void |
setModified(boolean modified)
Changes the modified state of the buffer and automatically updates the value returned by getLastModified to reflect the current time,
or resets it to the value of sourceLastModified if the buffer is being set
to an unmodified state. |
void |
updateContent()
If the buffer has an associated BufferUpdater, forces the buffer to fetch its current contents and discard the reference to the updater. |
static void |
updateModifiedBuffers()
Forces all lazy updates to be flushed to the appropriate buffers. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final Buffer[] EMPTY_ARRAY
public static final long MODIFIED_NEVER
public static final int STATE_MODIFIED
public static final int STATE_READONLY
public static final int STATE_LOADING
Constructor Detail |
public Buffer(Url url)
url
- The associated Url.Method Detail |
public Url getUrl()
public void revert()
sourceLastModified
property is set to
match the timestamp on the Url.
While this description is conceptually accurate, in practice the actual loading of the buffer's contents is deferred until the first time the contents are actually needed.
public void save(boolean useMultiLevelBackups) throws java.io.IOException
sourceLastModified
property
is reset to match the Url's new timestamp.useMultLevelBackups
- set to true for the backup to have
a multilevel backup. False for a backup with a single tilde
appended to the end of the filename.java.io.IOException
- If the Url cannot be written to.public void save() throws java.io.IOException
public void check()
sourceLastModified
property is compared with the
original Url's last modification to ensure that the in-memory
representation is up to date with changes that may have been made outside
the VFS.
If the Url has been updated then the action depends on the buffer's
state. If the buffer is not modified, the buffer is automatically updated
via a call to revert
. Otherwise, the VFS's VFSListeners are
notified to give the user a chance to make the choice. The call to
revert, if made, also updates the read-only state of the buffer to match
the current filesystem state.
public byte[] getContent()
public void setContent(byte[] content) throws ReadOnlyException
getOutputStream
when the complete contents have been
written.content
- An array of bytes representing the new content of the
buffer.com.borland.vfs.ReadOnlyException
- If the buffer is read only.public java.io.InputStream getInputStream()
getContent
.public java.io.OutputStream getOutputStream() throws ReadOnlyException
ReadOnlyException
- If the buffer is
read only.public int getSize()
public void setContent(BufferUpdater updater) throws ReadOnlyException
Sets the contents of the buffer in a lazy fasion using a BufferUpdater. All listeners are notified that the buffer's contents has changed, but the BufferUpdater is only queried to fetch the actual buffer contents when there is a request to read the new content.
Note that the Buffer may maintain a reference to the BufferUpdater
instance for an arbitrarily long period of time. To ensure that this
reference is released, call the Buffer's updateContent()
method to force the most recent updater's contents to be read
immediately.
BufferUpdater
public void updateContent()
If the buffer has an associated BufferUpdater, forces the buffer to fetch its current contents and discard the reference to the updater.
public long getLastModified()
public long getSourceLastModified()
public boolean isReadOnly()
public boolean isModified()
public void setModified(boolean modified)
getLastModified
to reflect the current time,
or resets it to the value of sourceLastModified if the buffer is being set
to an unmodified state.
Internal methods that alter the contents of the buffer invoke
setModified(true)
, even if the modified flag is already set.
modified
- True if the buffer should be marked as modified, false
otherwise.public boolean isLoading()
public static Buffer[] getModifiedBuffers()
public static int getModifiedBufferCount()
public static void updateModifiedBuffers()
public void addBufferListener(BufferListener listener)
listener
- The listener.public void removeBufferListener(BufferListener listener)
listener
- The listener.public void fireBufferChanged(BufferUpdater updater)
public void fireBufferLoaded()
public void fireBufferSaving()
public void fireBufferStateChanged(int oldState, int newState)
setState
, and indirectly by setModified
,
setReadOnly
and setLoading
if the new setting
causes a change in state. The states passed to listeners may be
interpreted using the constants described under getState
.oldState
- The state of the buffer prior to the change.newState
- The current state of the buffer.public byte[] getBufferContent(Buffer buffer)
revert()
to allow the
buffer to lazily load its own content.
If a java.io.FileNotFoundException
is thrown by the
Url's filesystem, an empty array is returned and the buffer is marked as
modified with a source timestamp of Buffer.MODIFIED_NEVER
.
getBufferContent
in interface BufferUpdater
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |