Package totalcross.io.sync
Class RemotePDBFile
- java.lang.Object
-
- totalcross.io.sync.RemotePDBFile
-
public final class RemotePDBFile extends java.lang.ObjectAllows you to access a pdb file on the device from the desktop during the conduit synchronization.
On PalmOS it may only be used to handle files on the device's internal memory.
-
-
Field Summary
Fields Modifier and Type Field Description protected intlastSearchedRecprotected intmodeprotected java.lang.Stringnameprotected booleanopenprotected intrecIndexstatic intRECORD_SIZE_AUTOprotected intwRecordSize
-
Constructor Summary
Constructors Constructor Description RemotePDBFile(java.lang.String name)Opens a remote PDBFile in READ_WRITE mode.RemotePDBFile(java.lang.String name, int mode)Opens a remote PDBFile in the given mode.RemotePDBFile(java.lang.String name, int mode, int recordSize)Opens a remote PDBFile with the given name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this PDBFile.voiddelete()Completely deletes this database, closing it first.voiddeleteRecord(int index)Deletes the given record index.protected voidfinalize()intgetNextModifiedRecordIndex()Returns the next modified record index.intgetRecordCount()Returns the number of records inside this databaseintgetRecordPos()Returns the current record position or -1 if there is no current record.static java.lang.String[]listPDBs(int crtr, int type)Lists the available PDBFiles on the device that has the given creator id and type.booleanreadRecord(int index, RemotePDBRecord rec)Fetches the given index, passing to the rec a DataStream to read the record information.intskipBytes(int n)Moves the cursor n bytes from the current position, moving backwards if n is negative, or forward if n is positive.
The cursor cannot be placed outside the stream limits, stopping at position 0 when moving backwards, or at the last position of the stream, when moving forward.booleanwriteRecord(int index, RemotePDBRecord rec)Write the record at the given index.
-
-
-
Constructor Detail
-
RemotePDBFile
public RemotePDBFile(java.lang.String name, int mode, int recordSize) throws IllegalArgumentIOException, FileNotFoundException, IOExceptionOpens a remote PDBFile with the given name. Important: only one PDBFile can be open at a time. Trying to open a new PDBFile before explicitly closing the former will throw a RuntimeException. Note that the Settings.dataPath, if set, is used by this method as the path to the PDBFile.- Parameters:
name- The PDBFile name on the formname.crtr.typemode- Can be PDBFile.READ_WRITE, PDBFile.CREATE (this one is non destructive: if the PDBFile don't exists, it will be created and it will remain open on READ_WRITE mode; if it exists, it will stay open on READ_WRITE mode). You can also or the mode with PDBFile.DB_ATTR_BACKUP or PDBFile.DB_ATTR_STREAM to set these attributes when creating a database (do NOT use the other attributes!)recordSize- Used only when writing records. If you plan to write records with fixed size, pass in the desired size. Otherwise, pass RemotePDBFile.RECORD_SIZE_AUTO to automatically expand or shrink the record.- Throws:
IOExceptionFileNotFoundExceptionIllegalArgumentIOException
-
RemotePDBFile
public RemotePDBFile(java.lang.String name) throws IllegalArgumentIOException, FileNotFoundException, IOExceptionOpens a remote PDBFile in READ_WRITE mode.
-
RemotePDBFile
public RemotePDBFile(java.lang.String name, int mode) throws IllegalArgumentIOException, FileNotFoundException, IOExceptionOpens a remote PDBFile in the given mode.
-
-
Method Detail
-
delete
public final void delete() throws IOExceptionCompletely deletes this database, closing it first.- Throws:
IOException
-
getRecordCount
public final int getRecordCount() throws IOExceptionReturns the number of records inside this database- Throws:
IOException
-
readRecord
public boolean readRecord(int index, RemotePDBRecord rec) throws IllegalArgumentIOException, IOExceptionFetches the given index, passing to the rec a DataStream to read the record information.
-
writeRecord
public boolean writeRecord(int index, RemotePDBRecord rec) throws IllegalArgumentIOException, IOExceptionWrite the record at the given index. IMPORTANT: if index is -1, the record is appended, otherwise, the given record is OVERWRITTEN. It is not possible to insert a record into a given position due to limitations of the native API. Also, passing a record index greater than the number of records may cause unexpected results.
-
getRecordPos
public int getRecordPos()
Returns the current record position or -1 if there is no current record.
-
deleteRecord
public final void deleteRecord(int index) throws IllegalArgumentIOException, IOExceptionDeletes the given record index. The record is immediately removed from the PDBFile and all subsequent records are moved up one position. IMPORTANT: due to this behaviour, if you plan to delete all records from a database, it is much faster if you delete them in REVERSE ORDER (from last to first). If you plan to delete all records, delete the whole database usingdeleteand then create it again.
-
skipBytes
public int skipBytes(int n)
Moves the cursor n bytes from the current position, moving backwards if n is negative, or forward if n is positive.
The cursor cannot be placed outside the stream limits, stopping at position 0 when moving backwards, or at the last position of the stream, when moving forward.- Parameters:
n- the number of bytes to move.- Returns:
- the number of bytes actually moved.
-
getNextModifiedRecordIndex
public final int getNextModifiedRecordIndex() throws IOExceptionReturns the next modified record index. Can be used with the readRecord to only retrieve the changed records since the last synchronization.- Throws:
IOException
-
close
public final void close() throws IOExceptionCloses this PDBFile.- Throws:
IOException
-
listPDBs
public static java.lang.String[] listPDBs(int crtr, int type)Lists the available PDBFiles on the device that has the given creator id and type. If you don't pass a creator id and/or a type, this method will return with NO RESULTS. Note that the Settings.dataPath, if set, is used by this method as the path to the PDBFiles.- Returns:
- A String array with the answer, or null if no db was found that matched the criteria.
-
finalize
protected void finalize()
- Overrides:
finalizein classjava.lang.Object
-
-