Current Page:
NeXtMidas Training
File Handlers
Lab 1
Part 1 (ctd.)
|
|
- Part 1 - The File Header (continued):
- Providing set/get methods for the header fields.
-
We need to make set and get methods for each of the fields in the header. If you
look back two pages you will see a table that
details the structure of the header.
-
When reading or unpacking data from a buffer, we want to use the unpack
methods provided by Convert.
These methods take in the buffer to access (header) and the byte offset
into the buffer (see the table). When unpacking a string, it is necessary to provide
the length of the string to read. When unpacking a numeric value, it is necessary
to indicate what byte representation is being used (here we are using EEEI).
-
When writing or packing data into a buffer, we want to use the pack
methods provided by Convert.
These methods are similar to the unpack methods, except that they have an
additional parameter for the value that is to be set.
-
For example, here are the set and get methods for XDelta:
public double getXDelta () {
return Convert.unpackD(header, 16, EEEI);
}
public void setXDelta (double val) {
Convert.packD(header, 16, val, EEEI);
}
-
The set and get methods for Version, Format, and XStart are left for you to do.
- continued on next page
|
|
|