• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

DataOutputStream

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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);
 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, shan chen
could you tell me what is header?
thx!
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
think you,Ta Ri Ki Sun
 
shan chen
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic