aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DataOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DataOutputStream" Watch "DataOutputStream" New topic
Author

DataOutputStream

shan chen
Ranch Hand

Joined: Apr 09, 2003
Posts: 70
The instruction says:
"All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream." It seems to me that it's better to use DataInputStream/DataOutputStream for io. But I did not find any method in DataOutputStream to location a position, which is important for update a record. RandomeAccessFile will be needed instead.
Any suggestion?
Thanks.
Erik Manor
Greenhorn

Joined: Mar 28, 2003
Posts: 12
I am using RandomAccessFile. RandomAccessFile implements DataOutput and DataInput interfaces as do DataOutputStream and DataInputStream. These interfaces are what gives DataInputStream/DataOutputStream their formats the instructions refer to so RandomAccessFile has them too.
Michael Dreese
Ranch Hand

Joined: Apr 02, 2003
Posts: 45
Originally posted by shan chen:
The instruction says:
"All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream." It seems to me that it's better to use DataInputStream/DataOutputStream for io. But I did not find any method in DataOutputStream to location a position, which is important for update a record. RandomeAccessFile will be needed instead.
Any suggestion?
Thanks.

I only used DataInputStream for getting all the header information and used RandomAccessFile for update/read/create records. If DataInputStream/DataOutputStream did implement the reset method, I would not have to use RandomAccessFile.
Cheers,
Michael
Vitaly Zhuravlyov
Greenhorn

Joined: Apr 11, 2003
Posts: 16
Originally posted by Michael Dreese:

If DataInputStream/DataOutputStream did implement the reset method, I would not have to use RandomAccessFile.

Try something like this
FileInputStream fis = new FileInputStream(databaseFileName);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
hi, shan chen
could you tell me what is header?
thx!
S. Ganapathy
Ranch Hand

Joined: Mar 26, 2003
Posts: 194
Hi Guys,
It seems some of you are working new project. How are you implementing primary key concept, like int recordNumber, where that field is not described in the db.db
And are you providing functionality for adding and deleting records in the UI where in the project add/delete/update records was not mentioned.
GVRao
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
Originally posted by damu liu:
hi, shan chen
could you tell me what is header?
thx!

a header is at the top of the file, and has 3 values in my assignment, first one identifies the file as a data file, second one tells me the length of a record, and the third tells me how many fields are in a record
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
Originally posted by Venkateswara Rao Gunturu:
Hi Guys,
It seems some of you are working new project. How are you implementing primary key concept, like int recordNumber, where that field is not described in the db.db
And are you providing functionality for adding and deleting records in the UI where in the project add/delete/update records was not mentioned.
GVRao


1) iro PK, I assign a record number, and store the recNo and its position in the file, I suppose the position in file could double as the record number.
2) no I dont implement those methods, I throw an exception instead but its never called because the requirements do not include creating and deleting records, if this was a real project then the guys adding these methods would have to consider the way I implemented the PK as mentioned in 1), fortunately there are no such guys
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
just out of interest , are you guys/girls opening your file once and thats it until the system shuts down ?
cos I have a habit of opening , reading/writing, closing
S. Ganapathy
Ranch Hand

Joined: Mar 26, 2003
Posts: 194
Hi Ta Ri Ki Sun,
In the db format/schema/data section, they never mentioned about record number. But they mentioned record number only in the DB interface file.
What assumption made you to implement record number in the db.db?
It is clearly mentioned, we should not touch anything in the db.db file.
Can you please help me?
GVRao
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
Originally posted by Venkateswara Rao Gunturu:
Hi Ta Ri Ki Sun,
In the db format/schema/data section, they never mentioned about record number. But they mentioned record number only in the DB interface file.
What assumption made you to implement record number in the db.db?
It is clearly mentioned, we should not touch anything in the db.db file.
Can you please help me?
GVRao


but I didn't touch the db.db at all, I did the next best thing, which is to write code that made provision for record numbers.
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
think you,Ta Ri Ki Sun
shan chen
Ranch Hand

Joined: Apr 09, 2003
Posts: 70

Originally posted by damu liu
hi, shan chen
could you tell me what is header?
thx!

Here is the format of my db file. First comes the hearder.
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file.
4 byte numeric, total overall length in bytes of each record
2 bytes numeric, number of fields in each record
Schema description section
... ...
Data Section
... ...

Seems many members are from the other side of the world. When I come back in the morning, there are many new posts. When at daytime here, I do not see much posts.
shan
shan chen
Ranch Hand

Joined: Apr 09, 2003
Posts: 70

Originally posted by
Try something like this
FileInputStream fis = new FileInputStream(databaseFileName);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);

Hi Vitaly,
DataInputStream works fine. The problem is with DataOutputStream. It does not provide method to move to a specific position, which is needed to write a particular record. So I have to use RandomAccessFile.
Shan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataOutputStream