public void write() throws IOException, xBaseJException
{
int i, j, k, ll = 512;
if (record_number == 0)
throw new xBaseJException("Invalid record number in write");
long longrecn = record_number;
nfile.seek(longrecn * 512);
nfile.writeInt(Util.x86(keys_in_this_Node));
ll -= 4; // sizeof(int)
for (i=0; i < keys_in_this_Node && i < keys_in_a_Node && key_expression[i] != null; i++)
{
if (key_expression[i] == null)
throw new xBaseJException("Missing node key expression at " + i);
if ((lower_level[0]==0) && (key_record_number[i]==0))
throw new xBaseJException("Logic mismatch, both pointers are zero");
nfile.writeInt(Util.x86(lower_level[i]));
ll-=4;
nfile.writeInt(Util.x86(key_record_number[i]));
ll-=4;
if (key_expression[i].getType() == 'N')
{ double d = key_expression[i].toDouble();
nfile.writeLong(Double.doubleToLongBits(d));
}
if (key_expression[i].getType() == 'C')
{
int x;
byte bytebuffer[];
try {bytebuffer = key_expression[i].toString().getBytes(DBF.encodedType);}
catch (UnsupportedEncodingException UEE){ bytebuffer = key_expression[i].toString().getBytes();}
for (x = 0; x < bytebuffer.length; x++)
key_buffer[x] = bytebuffer[x];
for (; x < key_expression_size; x++)
key_buffer[x] = 0;
nfile.write(key_buffer, 0, key_expression_size);
}
ll -= key_expression_size; // sizeof(2 ints) and full key length to its 4 byte alignment
j = key_expression_size % 4;
if (j>0) j = 4 - j; // 4 byte alignment
key_buffer[0] = 0;
for (k=0; k < j; k++) {
nfile.write(key_buffer[0]);
ll--;
}
} // for i
if ((branch==true) && (lower_level[i] == 0))
throw new xBaseJException("Logic mismatch, lower level pointer is zero");
nfile.writeInt(Util.x86(lower_level[i]));
ll -= 4; // sizeof(int)
if (ll > 0) {
// a Node is 512 bytes long;
byte temp[] = new byte[ll];