public class ObjectPDBFile extends PDBFile
ObjectPDBFile oc = new ObjectPDBFile("Test.DATA"); MyObject obj = new MyObject(); oc.resetSearch(); while (oc.nextObject(obj)) { // do something with obj }
Here's an example using unknown data. The two sections of code save a vector containing a number of Lines, Circles, and Squares (all implementing Storable) in no particular order, then loads it back in again.
// save data ObjectPDBFile oc=new ObjectPDBFile("Test.DATA",ObjectPDBFile.CREATE); for(int i=0,size=objs.getCount();i++) oc.addObject((Storable)objs.get(i)); oc.close(); // load data ObjectPDBFile oc=new ObjectPDBFile("Test.DATA"); oc.registerClass(new Line()); oc.registerClass(new Circle()); oc.registerClass(new Square()); objs=new Vector(); oc.resetSearch(); Storable obj; while ((obj=oc.nextObject())!=null) { objs.add(obj); } oc.close();
Modifier and Type | Field and Description |
---|---|
protected ByteArrayStream |
bs |
protected byte[] |
buf |
protected Vector |
classes |
protected int |
cnt |
protected DataStream |
ds |
CREATE, CREATE_EMPTY, DB_ATTR_APPINFODIRTY, DB_ATTR_BACKUP, DB_ATTR_COPY_PREVENTION, DB_ATTR_OK_TO_INSTALL_NEWER, DB_ATTR_READ_ONLY, DB_ATTR_RESET_AFTER_INSTALL, DB_ATTR_STREAM, READ_WRITE, REC_ATTR_DELETE, REC_ATTR_DIRTY, REC_ATTR_SECRET, REC_RELEASE
skipBuffer
Constructor and Description |
---|
ObjectPDBFile(java.lang.String name)
Construct a new ObjectPDBFile
|
ObjectPDBFile(java.lang.String name,
int type)
Constructs a new ObjectPDBFile
|
Modifier and Type | Method and Description |
---|---|
void |
addObject(Storable s)
Add an object to this PDBFile.
|
void |
deleteObjectAt(int i)
Delete an object from the PDBFile
|
byte |
getObjectAttribute(int i)
Get attributes of an object record from the PDBFile
|
void |
insertObjectAt(Storable s,
int i)
Insert an object to this PDBFile.
|
Storable |
loadObjectAt(int i)
Loads an object from the PDBFile.
|
void |
loadObjectAt(Storable s,
int i)
Load an object from the PDBFile into the given storable.
|
Storable |
nextObject()
Gets the next object in the PDBFile.
|
boolean |
nextObject(Storable s)
Gets the next object in the PDBFile and places it in the given storable.
|
void |
registerClass(Storable s)
Registers this class with the PDBFile.
|
void |
resetSearch()
Resets a counter for iterating through the PDBFile.
|
boolean |
setObjectAttribute(int i,
byte a)
Set attributes of an object record from the PDBFile
|
void |
setSearchIndex(int i)
Sets the search counter at the given index in the PDBFile.
|
int |
size()
Get the size of this PDBFile
|
addRecord, addRecord, close, delete, deleteRecord, finalize, getAttributes, getName, getRecordAttributes, getRecordCount, getRecordOffset, getRecordPos, getRecordSize, inspectRecord, listPDBs, listPDBs, readBytes, rename, resizeRecord, searchBytes, setAttributes, setRecordAttributes, setRecordOffset, setRecordPos, skipBytes, writeBytes
asInputStream, asOutputStream, asStream, asStream, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
protected Vector classes
protected int cnt
protected byte[] buf
protected ByteArrayStream bs
protected DataStream ds
public ObjectPDBFile(java.lang.String name, int type) throws IllegalArgumentIOException, FileNotFoundException, IOException
name
- the name of the PDBFiletype
- the mode to open the PDBFile withIOException
FileNotFoundException
IllegalArgumentIOException
public ObjectPDBFile(java.lang.String name) throws IllegalArgumentIOException, IOException
name
- the name of the PDBFileIOException
IllegalArgumentIOException
public void registerClass(Storable s)
s
- an instance of the class to register. The contents are ignored.public void addObject(Storable s) throws IllegalArgumentIOException, IOException
s
- the storable object to addIOException
IllegalArgumentIOException
public void insertObjectAt(Storable s, int i) throws IllegalArgumentIOException, IOException
s
- the storable object to addi
- the index where to insertIOException
IllegalArgumentIOException
public void loadObjectAt(Storable s, int i) throws IllegalArgumentIOException, IOException
s
- the object to load the data intoi
- the index in the PDBFile to load fromIOException
IllegalArgumentIOException
public Storable loadObjectAt(int i) throws IllegalArgumentIOException, IOException
i
- the index in the PDBFile to load fromIOException
IllegalArgumentIOException
public void deleteObjectAt(int i) throws IllegalArgumentIOException, IOException
i
- the index to delete fromIOException
IllegalArgumentIOException
public boolean setObjectAttribute(int i, byte a) throws IOException
i
- the index to set the attributea
- the attribute to set, use the REC_ATTR_XXXX constants from
PDBFile classIOException
public byte getObjectAttribute(int i) throws IOException
i
- the index to get the attribute fromIOException
public int size() throws IOException
IOException
public void resetSearch()
public void setSearchIndex(int i)
i
- the index to startpublic boolean nextObject(Storable s) throws IllegalArgumentIOException, IOException
IOException
IllegalArgumentIOException
public Storable nextObject() throws IOException
IOException