|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.org.blankaspect.nlf.Chunk
public class Chunk
This class implements a chunk of a Nested List File. The chunk, which is the primary structural unit of a Nested List File, consists of a header and binary data. The header consists of an identifier and a size field. The identifier field is of variable size, up to 256 bytes; the size of the size field is 8 bytes. The chunk size does not include the size of the header.
A chunk is created with the Document.createChunk(Id)
method, and is
added to a list with the ChunkList.appendChunk(Chunk)
method. A
chunk can be added only to a list that belongs to the same document as the chunk.
There are two special chunks: the list and the attributes
chunk, which have the reserved identifiers "$LIST"
and "$ATTR"
respectively.
ChunkList
Nested Class Summary | |
---|---|
static class |
Chunk.Base64Encoder
This singleton class implements a Base64 encoder for chunk data. |
static interface |
Chunk.Encoder
This interface specifies the methods that must be implemented by a class that encodes chunk data as character data for use as a text node of an XML file. |
static interface |
Chunk.Processor
This interface specifies the method that must be implemented by a class that processes the chunks that are visited in the traversal of a document tree or subtree. |
static interface |
Chunk.Reader
This interface specifies the methods that must be implemented by a class that reads chunk data from a data input. |
static interface |
Chunk.Writer
This interface specifies the methods that must be implemented by a class that writes chunk data to a data output. |
Field Summary | |
---|---|
protected Document |
document
|
protected Chunk.Encoder |
encoder
|
protected Id |
id
|
static long |
MAX_SIZE
|
static long |
MIN_SIZE
|
protected ChunkList |
parent
|
protected Chunk.Reader |
reader
|
protected long |
size
|
static int |
SIZE_SIZE
|
protected Chunk.Writer |
writer
|
Constructor Summary | |
---|---|
protected |
Chunk(Document document,
Id id)
Constructs a chunk with the specified owner document and identifier. |
Method Summary | |
---|---|
int |
compareTo(Chunk chunk)
Compares this chunk with the specified Chunk object. |
Document |
getDocument()
Returns the Nested List File document to which this chunk belongs. |
Chunk.Encoder |
getEncoder()
Returns the chunk encoder for this chunk. |
int |
getHeaderSize()
Returns the size of the chunk header (identifier and size). |
Id |
getId()
Returns the identifier of this chunk. |
java.lang.String |
getName()
Returns the name of this chunk. |
java.lang.String |
getNamespaceName()
Returns the namespace name that applies to this chunk. |
ChunkList |
getParent()
Returns the chunk list that contains this chunk, or null if this chunk has no parent. |
java.lang.String |
getPathname()
Returns the pathname of this chunk. |
Chunk.Reader |
getReader()
Returns the chunk reader for this chunk. |
long |
getSize()
Returns the size of this chunk in bytes. |
byte[] |
getSizeBytes(boolean littleEndian)
Returns the size of the chunk as an array of bytes, with the specified byte order. |
Chunk.Writer |
getWriter()
Returns the chunk writer for this chunk. |
boolean |
isAttributes()
Tests whether this chunk is an attributes chunk or a subclass of an attributes chunk. |
boolean |
isList()
Tests whether this chunk is a chunk list or a subclass of a chunk list. |
void |
setEncoder(Chunk.Encoder encoder)
Sets the chunk encoder for this chunk to the specified encoder. |
protected void |
setParent(ChunkList list)
Sets this chunk's parent to the specified list. |
void |
setReader(Chunk.Reader reader)
Sets the chunk reader for this chunk to the specified reader. |
void |
setSize(long size)
Sets the size of this chunk to the specified value. |
void |
setWriter(Chunk.Writer writer)
Sets the chunk writer for this chunk to the specified writer. |
org.w3c.dom.Element |
toXml(org.w3c.dom.Document xmlDocument)
Returns this chunk as an XML element of the specified document. |
void |
updateSize()
Updates the chunk's size field from the chunk writer, if one has been set. |
void |
writeHeader(java.io.DataOutput dataOutput)
Writes the chunk header (identifier and size) to the specified data output. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SIZE_SIZE
public static final long MIN_SIZE
public static final long MAX_SIZE
protected Document document
protected ChunkList parent
protected Id id
protected long size
protected Chunk.Reader reader
protected Chunk.Writer writer
protected Chunk.Encoder encoder
Constructor Detail |
---|
protected Chunk(Document document, Id id)
document
- the document to which the chunk will belong.id
- the chunk identifier.Method Detail |
---|
public int compareTo(Chunk chunk)
Chunk
object. The comparison is performed by
comparing the identifiers of the two objects using java.lang.String.compareTo(java.lang.String)
, which compares strings lexicographically by the
Unicode value of each character in the strings.
The result is
Because of the restrictions on identifiers, special chunks (ie, chunks with reserved identifiers) will always precede general chunks (ie, chunks with non-reserved identifiers).
compareTo
in interface java.lang.Comparable<Chunk>
chunk
- the Chunk
object with which the comparison is to be made.
0
(zero) if the identifier of this chunk is equal to the identifier of chunk
;0
if the identifier of this chunk is lexicographically less
than the identifier of chunk
;0
if the identifier of this chunk is lexicographically
greater than the identifier of chunk
.Id.compareTo(Id)
public Document getDocument()
public ChunkList getParent()
null
if this chunk has no parent.
null
if this chunk
has no parent.setParent(ChunkList)
public Id getId()
public long getSize()
-1
indicates that the size is invalid
and that the size of the chunk should be obtained by another means (eg, from getWriter()
.getLength()
).
setSize(long)
,
updateSize()
,
Chunk.Writer.getLength()
public Chunk.Reader getReader()
setReader(Reader)
,
Chunk.Reader
public Chunk.Writer getWriter()
setWriter(Writer)
,
Chunk.Writer
public Chunk.Encoder getEncoder()
toXml(org.w3c.dom.Document)
to encode the chunk data for use as a text node of an XML file.
setEncoder(Encoder)
,
Chunk.Encoder
public void setSize(long size)
size
- the value to which the size of this chunk is to be set.getSize()
,
updateSize()
public void setReader(Chunk.Reader reader)
reader
- the Reader
that is to be this chunk's reader.getReader()
public void setWriter(Chunk.Writer writer)
writer
- the Writer
that is to be this chunk's writer.getWriter()
public void setEncoder(Chunk.Encoder encoder)
toXml(org.w3c.dom.Document)
to encode the chunk data for use as a text
node of an XML file.
encoder
- the Encoder
that is to be this chunk's encoder.getEncoder()
public boolean isAttributes()
true
if this chunk is an attributes chunk or a subclass of an attributes chunk;
false
otherwise.public boolean isList()
true
if this chunk is a chunk list or a subclass of a chunk list; false
otherwise.public void updateSize()
size
field from the chunk writer, if one has been set. The chunk size is
set to the value returned by the chunk writer's getLength()
method.
getSize()
,
setSize(long)
,
Chunk.Writer.getLength()
public java.lang.String getNamespaceName()
null
local namespace name that is encountered in an ancestor when ascending the document
tree. If none of the chunk's ancestors has a local namespace name, null
is returned.
null
if no namespace name applies.ChunkList.getNamespaceName()
public java.lang.String getName()
ChunkList.getName()
public java.lang.String getPathname()
public int getHeaderSize()
public byte[] getSizeBytes(boolean littleEndian)
littleEndian
- true
if the byte order is little-endian; false
if the byte
order is big-endian.
public void writeHeader(java.io.DataOutput dataOutput) throws java.io.IOException
dataOutput
- the data output to which the chunk header is to be written.
java.io.IOException
- if an I/O error occurs.public org.w3c.dom.Element toXml(org.w3c.dom.Document xmlDocument) throws org.w3c.dom.DOMException, java.io.IOException, NlfException
Base64Encoder
.
xmlDocument
- the XML document that is to be the owner of the element that is created.
org.w3c.dom.DOMException
- if an exception occurs in creating the XML element.
java.io.IOException
- if an I/O error occurs in reading the chunk data.
NlfException
- if
protected void setParent(ChunkList list)
list
- the list that is to be this chunk's parent.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |