Java Reference
In-Depth Information
// Get the bytes for this item.
b = baos.toByteArray();
dos = null;
baos = null;
return b;
}
public void fromBytes(byte[] b) {
ByteArrayInputStream bais = new ByteArrayInputStream(b);
DataInputStream dis = new DataInputStream(bais);
// Read each tag, then each field
try
{
while(true) {
int tag = dis.readInt();
switch(tag) {
case FIELD_VERSION:
// Don't check version; there's only one
dis.readInt();
break;
case FIELD_LOCATION:
setLocation(dis.readUTF());
break;
case FIELD_FORECAST:
setForecast(dis.readUTF());
break;
}
}
}
catch (Exception e) {}
dis = null;
bais = null;
}
}
A location in memory actually has three fields, two of which are visible to its clients:
location : A text string indicating the location for the forecast
forecast : A text string indicating the weather at the location
recordId : An integer indicating the record ID of the record in the record store (if any),
or the value NO_ID indicating the record has not yet been stored in the record store
 
Search WWH ::




Custom Search