Package org.eclipse.compare
Class BufferedContent
- java.lang.Object
-
- org.eclipse.compare.BufferedContent
-
- All Implemented Interfaces:
IContentChangeNotifier,IStreamContentAccessor
- Direct Known Subclasses:
ResourceNode
public abstract class BufferedContent extends Object implements IContentChangeNotifier, IStreamContentAccessor
Abstract implementation for a bufferedIStreamContentAccessor.Subclasses must implement the
createStreammethod to connect the buffered content with a streamable source (e.g., a file).As long as the contents of
BufferedContentis only retrieved as an input stream (by means ofgetContents) and theBufferedContentis not modified (withsetContent) no buffering takes place. Buffering starts when either methodgetContentorsetContentis called.- See Also:
IContentChangeNotifier,IStreamContentAccessor
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBufferedContent()Creates a buffered stream content accessor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddContentChangeListener(IContentChangeListener listener)Adds a content change listener to this notifier.protected abstract InputStreamcreateStream()Creates and returns a stream for reading the contents.voiddiscardBuffer()Discards the buffered content.protected voidfireContentChanged()Notifies all registeredIContentChangeListeners of a content change.byte[]getContent()Returns the contents as an array of bytes.InputStreamgetContents()Returns an openInputStreamfor this object which can be used to retrieve the object's content.voidremoveContentChangeListener(IContentChangeListener listener)Removes the given content changed listener from this notifier.voidsetContent(byte[] contents)Sets the contents.
-
-
-
Method Detail
-
getContents
public InputStream getContents() throws CoreException
Description copied from interface:IStreamContentAccessorReturns an openInputStreamfor this object which can be used to retrieve the object's content. The client is responsible for closing the stream when finished. Returnsnullif this object has no streamable contents.- Specified by:
getContentsin interfaceIStreamContentAccessor- Returns:
- an input stream containing the contents of this object
- Throws:
CoreException- if the contents of this object could not be accessed
-
createStream
protected abstract InputStream createStream() throws CoreException
Creates and returns a stream for reading the contents.Subclasses must implement this method.
- Returns:
- the stream from which the content is read
- Throws:
CoreException- if the contents could not be accessed
-
setContent
public void setContent(byte[] contents)
Sets the contents. Registered content change listeners are notified.- Parameters:
contents- the new contents
-
getContent
public byte[] getContent()
Returns the contents as an array of bytes.- Returns:
- the contents as an array of bytes, or
nullif the contents could not be accessed
-
discardBuffer
public void discardBuffer()
Discards the buffered content.
-
addContentChangeListener
public void addContentChangeListener(IContentChangeListener listener)
Description copied from interface:IContentChangeNotifierAdds a content change listener to this notifier. Has no effect if an identical listener is already registered.- Specified by:
addContentChangeListenerin interfaceIContentChangeNotifier- Parameters:
listener- a content changed listener
-
removeContentChangeListener
public void removeContentChangeListener(IContentChangeListener listener)
Description copied from interface:IContentChangeNotifierRemoves the given content changed listener from this notifier. Has no effect if the listener is not registered.- Specified by:
removeContentChangeListenerin interfaceIContentChangeNotifier- Parameters:
listener- a content changed listener
-
fireContentChanged
protected void fireContentChanged()
Notifies all registeredIContentChangeListeners of a content change.
-
-