Troubleshooting guide
85
4: Managing data
int length = data.readShort();
byte[] bytes = new byte[length];
switch (data.readByte())
{
case FIELDTAG_FIRST_NAME:
data.readFully(bytes);
//trim null-terminator
contact.setFirst(new String(bytes).trim());
break;
case FIELDTAG_LAST_NAME:
data.readFully(bytes);
contact.setLast(new String(bytes).trim());
break;
case FIELDTAG_EMAIL_ADDRESS:
data.readFully(bytes);
contact.setEmail(new String(bytes).trim());
break;
default:
data.readFully(bytes);
//other fields not supported
break;
}
}
return contact;
}
catch (EOFException e)
{
System.err.println(e.toString());
}
return null;
}
//SyncCollection methods----------
public boolean addSyncObject(SyncObject object)
{
// add a contact to the persistent store
_contacts.addElement(object);
_persist.setContents( _contacts );
_persist.commit();
// we want to let any collection listeners we have that the collection has been
changed
for( int i=0; i<_listeners.size(); i++ )
{
CollectionListener cl = (CollectionListener)_listeners.elementAt( i );
cl.elementAdded( this, object );
}
return true;
}
public boolean updateSyncObject(SyncObject oldObject, SyncObject newObject)
{
return false; //na - this method would look much the same as addSyncObject
}
public boolean removeSyncObject(SyncObject object)
{
return false; //na - this method would look much the same as addSyncObject