|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.borland.primetime.vfs.Buffer
Buffer is the concrete implementation for all virtual file system buffer management. 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
|
static long |
MODIFIED_NEVER
|
static int |
STATE_LOADING
|
static int |
STATE_MODIFIED
|
static int |
STATE_READONLY
|
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()
Checks the underlying representation of this buffer 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()
Conceptually, this 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()
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.
In practice the actual loading of the buffer's contents is deferred until the first time it is accessed.
public void save() throws java.io.IOException
sourceLastModified
property
is reset to match the Url's new timestamp.public void check()
sourceLastModified
property is compared with the original Url's last modification.
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.
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.public java.io.InputStream getInputStream()
getContent
.public java.io.OutputStream getOutputStream() throws ReadOnlyException
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 information is only read if there is an actual request to read the new contents.
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 static Buffer[] getModifiedBuffers()
public static int getModifiedBufferCount()
public static void updateModifiedBuffers()
public boolean isLoading()
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
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |