org.freecompany.redline.header

Class AbstractHeader

public abstract class AbstractHeader extends Object

Nested Class Summary
abstract classAbstractHeader.AbstractEntry<T>
interfaceAbstractHeader.Entry<T>
interfaceAbstractHeader.Tag
Field Summary
protected Map<Integer,Entry<?>>entries
protected static intENTRY_SIZE
protected static intHEADER_HEADER_SIZE
protected static intMAGIC_WORD
protected Map<Entry<?>,Integer>pending
protected Map<Integer,AbstractHeader.Tag>tags
Method Summary
intcount()
Entry<?>createEntry(int tag, int type, int count)
protected Entry<?>createEntry(int type)
protected ByteBuffergetData(ByteBuffer index)
Writes the data section of the file, starting at the current position which must be immediately after the header section.
Entry<?>getEntry(AbstractHeader.Tag tag)
Entry<?>getEntry(int tag)
protected ByteBuffergetHeader()
Memory maps the portion of the destination file that will contain the header structure header and advances the file channels position.
protected ByteBuffergetIndex()
Memory maps the portion of the destination file that will contain the index structure header and advances the file channels position.
Map<Entry<?>,Integer>getPending()
protected abstract booleanpad()
intread(ReadableByteChannel in)
Reads the entire header contents for this channel and returns the number of entries found.
Entry<?>readEntry(int tag, int type, int offset, int count, ByteBuffer data)
voidremoveEntry(Entry<?> entry)
StringtoString()
intwrite(WritableByteChannel out)
Writes this header section to the provided file at the current position and returns the required padding.
protected intwriteData(Collection<ByteBuffer> buffers, ByteBuffer index, Entry<?> entry, int offset)

Field Detail

entries

protected final Map<Integer,Entry<?>> entries

ENTRY_SIZE

protected static final int ENTRY_SIZE

HEADER_HEADER_SIZE

protected static final int HEADER_HEADER_SIZE

MAGIC_WORD

protected static final int MAGIC_WORD

pending

protected final Map<Entry<?>,Integer> pending

tags

protected final Map<Integer,AbstractHeader.Tag> tags

Method Detail

count

public int count()

createEntry

public Entry<?> createEntry(int tag, int type, int count)

createEntry

protected Entry<?> createEntry(int type)

getData

protected ByteBuffer getData(ByteBuffer index)
Writes the data section of the file, starting at the current position which must be immediately after the header section. Each entry writes its corresponding index into the provided index buffer and then writes its data to the file channel.

Returns: the total number of bytes written to the data section of the file.

getEntry

public Entry<?> getEntry(AbstractHeader.Tag tag)

getEntry

public Entry<?> getEntry(int tag)

getHeader

protected ByteBuffer getHeader()
Memory maps the portion of the destination file that will contain the header structure header and advances the file channels position. The resulting buffer will be prefilled with the necesssary magic data and the correct index count, but will require an integer value to be written with the total data section size once data writing is complete.

This method must be invoked before mapping the index or data sections.

getIndex

protected ByteBuffer getIndex()
Memory maps the portion of the destination file that will contain the index structure header and advances the file channels position. The resulting buffer will be ready for writing of the entry indexes.

This method must be invoked before mapping the data section, but after mapping the header.

getPending

public Map<Entry<?>,Integer> getPending()

pad

protected abstract boolean pad()

read

public int read(ReadableByteChannel in)
Reads the entire header contents for this channel and returns the number of entries found.

readEntry

public Entry<?> readEntry(int tag, int type, int offset, int count, ByteBuffer data)

removeEntry

public void removeEntry(Entry<?> entry)

toString

public String toString()

write

public int write(WritableByteChannel out)
Writes this header section to the provided file at the current position and returns the required padding. The caller is responsible for adding the padding immediately after this data.

writeData

protected int writeData(Collection<ByteBuffer> buffers, ByteBuffer index, Entry<?> entry, int offset)