• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urlyBird requirement clarification

 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirement says " All numeric are stored in the header information use the formats of the DataInputStream and DataOutputStream classes."


Is there a period after 'header information'?
What does format implies here?
Is sun suggesting to use DataInputStream and DataOutputStream?

I understand that the seek functionality can be attained by specifying offset in readByte(offset, length) command. I wonder what is meant by "the format for DataInputStream". If somebody can put some light in the right direction that will be great.

Thanks in advance.
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its referring to the numerical information with regards to built in data types like short, intetger etc. Basically you have to directly read the data as integers or shorts, and not read them as a string and parse them.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jiju,

Welcome to JavaRanch and this forum.

Sun seem to have found an obscure way of telling us that the data is in a Java readable format. That is, you don't have to worry about whether it uses big-endian data or little-endian data, or converting from EBCDIC or ....

Basically you can use any I/O classes you like. If you want to, you can use DataInputStream and DataOutputStream classes, or you can move to RandomAccessFile (which uses the same underlying data format), or (as long as your instructions don't explicitly dissalow it) any of the NIO classes.

Regards, Andrew
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inuka and Andrew,
Thanks for your time.

Now it is clear to me. Now I am thinking which file accessor class to choose.

RandomAccessFile implements both DataInput and DataOutput.
DataInputStream inplements DataInput
DataOutputStream implements DataOutput

The method I like to use is

readFully(byte[] b, int off, int len) //Reads len bytes from an input stream.

I am curious to know which among DataXXputStream (XX-in, out) and RandomAccessFile is more effecient and flexible.

Some thoughts I came across are
1. having separate reader and writer objects appeals to me for the code can be synchronozed on writer object.
2. having RandomAccessFile will enable us to have a single object to do read and write.

What else should I consider in choosing file accessor class?
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I found the answer to my question.
RandomAccessFile is appropriate since it have the seek method.

The offset in
readFully(byte[] b, int off, int len)
will not replace seek function as I thought.

off:int (in the signature above) merely specifies a position in b:byte[] array

Jiju
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic