This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Reading and writting the 2 byte flag indicator

 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • 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));
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • 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
 
Noah Le
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
  • 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));

--------------------------------------------------------------------------------
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
i don't know how i skipped over trying to test that one but it
works. thanks Davidd !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic