public void open (SyncProperties props){
// Tell the log we are starting
Log.startSync();
try {
// create output file
String fname = props.pathName + props.localName;
FileOutputStream out = new FileOutputStream (fname);
Log.AddEntry ("MyConduit: saving information to '"
+ fname + "'", Log.TEXT, false);
// open custom database
byte flags = (byte)(SyncManager.OPEN_READ |
SyncManager.OPEN_WRITE |
SyncManager.OPEN_EXCLUSIVE);
int db = SyncManager.openDB (props.remoteNames[0],
(short)0, flags);
// find out how many memo records there are
int count = SyncManager.getDBRecordCount (db);
// create a new Record
CMyRecord rec = new CMyRecord ();
// Loop over all records
for (int i = 0; i < count; i++) {
// read next record
rec.setIndex (i);
SyncManager.readRecordByIndex (db, rec);
// build output string.
byte[] addr = rec.getBytes ("inetaddr");
String msg = "[" + i + "] **********\r\nName: " +
rec.getString ("name") +
"\r\nURL: " + rec.getString ("url") +
"\r\nIP: " +
((int)addr[0] & 0xFF) + "." +
((int)addr[1] & 0xFF) + "." +
((int)addr[2] & 0xFF) + "." +
((int)addr[3] & 0xFF) +
"\r\nPort: " + rec.getShort("port") +
"\r\nLogin: " + rec.getString ("login") +
"\r\n";
// print it out to file
out.write(msg.getBytes());
}
// close database
SyncManager.closeDB (db);
// close file
out.flush();
out.close();
// Signal log we are successful
Log.AddEntry("OK MyConduit", Log.TEXT, false);
Log.endSync();
} catch (Throwable t) {
// If there was an error, dump the stack trace
// and tell the log the conduit failed
t.printStackTrace();
Log.abortSync();
}
}
|