Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Please Help - Writting and Reading 2 byte flag

 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading and writting to my file fine except for the record
indicator (2 byte flag). Part of my database schema states
"Data section. (offset into file equal to "offset to start of record zero" value) Repeat to end of file:
2 byte flag. 00 implies valid record, 0x8000 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information"

My question is how do I write/read 0X8000 to the file as a 2 byte flag???
When I read this flag I use the following code:
byte[] b = new byte[2];
raf.read(b); // Read the two bit flag
Where b[0] = 0 and b[1] = 0 for a valid record. But I don't understand how to write 0X8000 and if raf.read(b) will correctly read 0X8000. If I read 0X8000 using read(b) what will b[0] and b[1] equal (I cant test this
yet because I don't know how to write 0X8000 as a two byte flag yet).
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,
That "2 bytes flag" is a short. 0X8000 is (short) -32768 while 00 is (short) 0. So using readShort() / writeShort() should solve your issue.
Best,
Phil.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic