• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin

NX: Please Help - Writting and Reading 2 byte flag

Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic