• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Reading and writting the 2 byte flag indicator

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My directions have:
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 .
----------------------------------------------------------------------------
Two questions regarding this:
1. How do you write 0x8000 to the file to mark an entry as deleted.
What format is this? I have used numerous raf.write() and raf.writeX()
forms but they all produce junk.
2. Also, how do you read this 2 byte flag indicator?
I have read the flag using multiple forms
of raf.read() and raf.readX(), but none of them ouput 00. For example the following outputs 2. So I must not be reading it correctly.
byte[] record = new byte[2];
System.out.println(raf.read(record));
 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I used file channels and put...
byte[] flag ={-128,0};
into a bytebuffer and then wrote it to the channel.
Or you can use any of the methods in RandomAccessFile or DataOutputStream.
Remember when you write the actual fields to the file that they have to be encoded.
Tony
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can cast 0x8000 to a short and use a file channel or a stream to write it to output. or you could use RandomAccessFile's writeShort(int) method.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help on number 2:
2. Also, how do you read this 2 byte flag indicator?
I have read the flag using multiple forms
of raf.read() and raf.readX(), but none of them ouput 00. For example the following outputs 2. So I must not be reading it correctly.
byte[] record = new byte[2];
System.out.println(raf.read(record));

--------------------------------------------------------------------------------
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Bill,
Did you try RandomAccessFile's readShort()?
Regards
Davidd
 
Bill Robertson
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 don't know how i skipped over trying to test that one but it
works. thanks Davidd !!!
 
Get me the mayor's office! I need to tell her about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic