public abstract class ObjectDatafile
extends java.lang.Object
| Constructor and Description |
|---|
ObjectDatafile() |
ObjectDatafile(java.lang.String filename) |
| Modifier and Type | Method and Description |
|---|---|
void |
appendRecord(java.lang.Object record)
Appends a record to the end of the file.
|
void |
clear() |
void |
close() |
int |
compare(int a,
int b)
Compares the two indexed records.
|
int |
compare(int index,
java.lang.Object key)
Compares the record to the given key.
|
protected int |
compareImp(java.io.RandomAccessFile filet,
long seekA,
long seekB)
Subclasses may override this to compare two records directly.
|
protected int |
compareImp(java.io.RandomAccessFile filet,
java.lang.Object key)
Subclasses may override this to compare the seeked-to record to a key.
|
int |
findClosest(java.lang.Object key)
Returns the index of the "closest" record matching the given key (this
would be the insertion point if you were to insert the given key) Uses
binary search, so the file has to be sorted first.
|
protected java.io.RandomAccessFile |
getFile()
If you just have to bang on the file, use this.
|
protected int |
getHeaderSize()
Get your header size, in case you've forgotten already.
|
protected int |
getRecordSize()
Get your record size, in case you've forgotten already.
|
int |
getSize()
Returns size of data file, in records.
|
void |
openRead() |
void |
openWrite() |
java.lang.Object |
readHeader()
Get object from header.
|
protected java.lang.Object |
readHeaderImp(java.io.RandomAccessFile filet)
Override this if you want something returned from read header.
|
java.lang.Object |
readKey(int index)
Reads a key from the given slot.
|
protected java.lang.Object |
readKeyImp(java.io.RandomAccessFile filet)
Subclasses may override this to read the key for a record.
|
java.lang.Object |
readRecord(int index)
Reads a record from the given slot.
|
void |
readRecord(int index,
java.lang.Object recyclable)
This might be faster - recycle your own object rather than having me
create a new one for you.
|
protected abstract void |
readRecordImp(java.lang.Object recycleMe,
java.io.RandomAccessFile filet)
Subclasses must override this to read an object from the fixed-length
format, given an object to put the results into.
|
protected abstract java.lang.Object |
readRecordImp(java.io.RandomAccessFile filet)
Subclasses must override this to read an object from the fixed-length
format.
|
int |
search(java.lang.Object key)
Returns the index of the record matching the given key; -1 if it can't
find one.
|
protected void |
setHeaderSize(int newSize)
Use this to set your header size.
|
protected void |
setRecordSize(int newSize)
Use this to set your record size in bytes.
|
void |
sort()
Sorts the file using quicksort.
|
void |
writeHeader(java.lang.Object newHeader)
Write object to header.
|
protected void |
writeHeaderImp(java.lang.Object header,
java.io.RandomAccessFile filet)
Override this if you want it to do anything.
|
void |
writeRecord(int index,
java.lang.Object rec)
Writes a record into the given slot.
|
protected abstract void |
writeRecordImp(java.lang.Object source,
java.io.RandomAccessFile filet)
Subclasses must override this to write out the object in the desired
form.
|
public ObjectDatafile()
public ObjectDatafile(java.lang.String filename)
protected abstract void writeRecordImp(java.lang.Object source,
java.io.RandomAccessFile filet)
throws java.io.IOException
java.io.IOExceptionprotected abstract java.lang.Object readRecordImp(java.io.RandomAccessFile filet)
throws java.io.IOException
java.io.IOExceptionprotected abstract void readRecordImp(java.lang.Object recycleMe,
java.io.RandomAccessFile filet)
throws java.io.IOException
The RandomAccessFile is advanced to the correct spot; just read away.
java.io.IOExceptionprotected java.lang.Object readKeyImp(java.io.RandomAccessFile filet)
throws java.io.IOException
java.io.IOExceptionprotected int compareImp(java.io.RandomAccessFile filet,
long seekA,
long seekB)
throws java.io.IOException
java.io.IOExceptionprotected int compareImp(java.io.RandomAccessFile filet,
java.lang.Object key)
throws java.io.IOException
java.io.IOExceptionprotected void setRecordSize(int newSize)
protected int getRecordSize()
protected void setHeaderSize(int newSize)
protected int getHeaderSize()
protected java.lang.Object readHeaderImp(java.io.RandomAccessFile filet)
throws java.io.IOException
java.io.IOExceptionprotected void writeHeaderImp(java.lang.Object header,
java.io.RandomAccessFile filet)
throws java.io.IOException
java.io.IOExceptionprotected java.io.RandomAccessFile getFile()
public void clear()
throws java.io.IOException
java.io.IOExceptionpublic void openRead()
throws java.io.IOException
java.io.IOExceptionpublic void openWrite()
throws java.io.IOException
java.io.IOExceptionpublic void close()
throws java.io.IOException
java.io.IOExceptionpublic void appendRecord(java.lang.Object record)
throws java.io.IOException
java.io.IOExceptionpublic void writeRecord(int index,
java.lang.Object rec)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.Object readRecord(int index)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.Object readKey(int index)
throws java.io.IOException
java.io.IOExceptionpublic void readRecord(int index,
java.lang.Object recyclable)
throws java.io.IOException
java.io.IOExceptionpublic int getSize()
throws java.io.IOException
java.io.IOExceptionpublic int compare(int a,
int b)
throws java.io.IOException
java.io.IOExceptionpublic int compare(int index,
java.lang.Object key)
throws java.io.IOException
java.io.IOExceptionpublic void sort()
throws java.io.IOException
java.io.IOExceptionpublic int search(java.lang.Object key)
throws java.io.IOException
java.io.IOExceptionpublic int findClosest(java.lang.Object key)
public java.lang.Object readHeader()
throws java.io.IOException
java.io.IOExceptionpublic void writeHeader(java.lang.Object newHeader)
throws java.io.IOException
java.io.IOException