aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Reading and writting the 2 byte flag indicator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Reading and writting the 2 byte flag indicator" Watch "NX: Reading and writting the 2 byte flag indicator" New topic
Author

NX: Reading and writting the 2 byte flag indicator

Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
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

Joined: Jul 03, 2003
Posts: 435
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

Joined: Aug 12, 2003
Posts: 4
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

Joined: Mar 21, 2003
Posts: 234
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

Joined: Jul 28, 2003
Posts: 62
Hi, Bill,
Did you try RandomAccessFile's readShort()?
Regards
Davidd
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
i don't know how i skipped over trying to test that one but it
works. thanks Davidd !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Reading and writting the 2 byte flag indicator