gate.corpora
Class DocumentContentImpl

java.lang.Object
  |
  +--gate.corpora.DocumentContentImpl
All Implemented Interfaces:
DocumentContent, Serializable

public class DocumentContentImpl
extends Object
implements DocumentContent

Represents the commonalities between all sorts of document contents.

See Also:
Serialized Form

Field Summary
(package private)  String content
          Just for now - later we have to cater for different types of content.
private static boolean DEBUG
          Debug flag
private static int INTERNAL_BUFFER_SIZE
          Buffer size for reading 16k is 4 times the block size on most filesystems so it should be efficient for most cases
(package private)  String originalContent
          For preserving the original content of the document.
(package private) static long serialVersionUID
          Freeze the serialization UID.
 
Constructor Summary
DocumentContentImpl()
          Default construction
DocumentContentImpl(String s)
          For ranges
DocumentContentImpl(URL u, String encoding, Long start, Long end)
          Contruction from URL and offsets.
 
Method Summary
(package private)  void edit(Long start, Long end, DocumentContent replacement)
          Propagate changes to the document content.
 boolean equals(Object other)
          Two documents are the same if their contents is the same
 DocumentContent getContent(Long start, Long end)
          The contents under a particular span.
 String getOriginalContent()
          Return the original content of the document received during the loading phase or on construction from string.
 int hashCode()
          Calculate the hash value for the object.
(package private)  boolean isValidOffset(Long offset)
          Check that an offset is valid
(package private)  boolean isValidOffsetRange(Long start, Long end)
          Check that both start and end are valid offsets and that they constitute a valid offset range
 Long size()
          The size of this content (e.g.
 String toString()
          Returns the String representing the content in case of a textual document.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

INTERNAL_BUFFER_SIZE

private static final int INTERNAL_BUFFER_SIZE
Buffer size for reading 16k is 4 times the block size on most filesystems so it should be efficient for most cases

content

String content
Just for now - later we have to cater for different types of content.

originalContent

String originalContent
For preserving the original content of the document. The edit command didn't affect on the original content. If you construct the content by URL the originalContent will keep whole information retrieved by URL even you set some start and end.

serialVersionUID

static final long serialVersionUID
Freeze the serialization UID.
Constructor Detail

DocumentContentImpl

public DocumentContentImpl()
Default construction

DocumentContentImpl

public DocumentContentImpl(URL u,
                           String encoding,
                           Long start,
                           Long end)
                    throws IOException
Contruction from URL and offsets.

DocumentContentImpl

public DocumentContentImpl(String s)
For ranges
Method Detail

edit

void edit(Long start,
          Long end,
          DocumentContent replacement)
Propagate changes to the document content.

getContent

public DocumentContent getContent(Long start,
                                  Long end)
                           throws InvalidOffsetException
The contents under a particular span.
Specified by:
getContent in interface DocumentContent

toString

public String toString()
Returns the String representing the content in case of a textual document. NOTE: this is a temporary solution until we have a more generic one.
Overrides:
toString in class Object

size

public Long size()
The size of this content (e.g. character length for textual content).
Specified by:
size in interface DocumentContent

isValidOffset

boolean isValidOffset(Long offset)
Check that an offset is valid

isValidOffsetRange

boolean isValidOffsetRange(Long start,
                           Long end)
Check that both start and end are valid offsets and that they constitute a valid offset range

equals

public boolean equals(Object other)
Two documents are the same if their contents is the same
Overrides:
equals in class Object

hashCode

public int hashCode()
Calculate the hash value for the object.
Overrides:
hashCode in class Object

getOriginalContent

public String getOriginalContent()
Return the original content of the document received during the loading phase or on construction from string.