aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: (Contractors) File I/O class 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 "NX: (Contractors) File I/O class" Watch "NX: (Contractors) File I/O class" New topic
Author

NX: (Contractors) File I/O class

Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Hi guys,
I have Contractors assignment. The instruction mentioned DataInputStream and DataOutputStream classes. Does that mean I have to use these two classes to read and write the db file?
Nitti


SCJP, SCWCD, SCJD, (SCEA, MCSD.net)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Not necessarily. RandomAccessFile implements the same methods. You could also write your own methods to (for example) convert four consecutive bytes into an int - it's pretty simple. But there's no good reason to do this, that I see; you might as well just use one of the classes already available.
Note - I use a FileChannel to read the main part of the file, because it's much faster. FileChannel doesn't have the DataInput / DataOutput methods. If I were to read the header with FileChannel, I'd have to do a little more work to extract the data. But instead I just use RandomAccessFile for the header (slower, but short) and save the FileChannel for the main body.


"I'm not back." - Bill Harding, Twister
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Hi,
I agree with Jim, I also use a FileChannel on top of the RandomAccessFile. To be honest: I also use it for obtaining the header information...
- get a FileChannel from your randomAccessFile
- create a byteBuffer which contains the data from your FileChannel
- use the methods provided in the ByteBuffer to extract the various datatypes
Greetings,
TK
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Thank you guys... I will check it out.
Nitti
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
Hi
I have the same assignment but I dont really understand the data file format described since I am used to accessing a relational database I have never used a flat file database.
what does Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record
mean , also the Data section, and schemea description section
how do I go about in reading and writing the data in that file and each fields name?
btw my file is db-2x3.db
any help and explanation would be much appreciated .
Thanks


BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Hi Billy,
Originally posted by Billy Tsai:

4 byte numeric, magic cookie value. Identifies this as a data file

I think the magic cookie is for Sun's people or program to identify the database format for their internal use. In my case, the magic cookie is 0023 if I didn't read it wrong.
Originally posted by Billy Tsai:

2 byte numeric, number of fields in each record

It's just what it says. If you don't want to hardcode the number of fields, you may use this value to read how many fields in this database file format. At least, that's what I'm doing. I have a for loop using this value to loop through the schemea description and save it.
Originally posted by Billy Tsai:

also the Data section, and schemea description section
how do I go about in reading and writing the data in that file and each fields name?

In my case, I have a method to read the file header and save the field names and field length. I also save the position of the first record after I'm done reading the header.
Originally posted by Billy Tsai:

btw my file is db-2x3.db

I have the same database file. Just double check... do you have 34 records as well?
Nitti
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
Thanks for your explanation
are you using NIO , fileChannel and RandomAccessFile to aceess the file?
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
I am assuming that int recNo in the methods is the owner field which represent customer holding this record with field length of 8 in the database file.
is that right?
please clarify thanks
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Billy,
are you using NIO , fileChannel and RandomAccessFile to aceess the file?

Yes.
I am assuming that int recNo in the methods is the owner field which represent customer holding this record with field length of 8 in the database file.
is that right?

No that's not the idea: the idea is to use the record number (1,2,3, etc.) as unique key:
http://www.coderanch.com/t/183198/java-developer-SCJD/certification/NX-No-Primary-key
Greetings,
TK
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
HI
I need to clarify something, in the (NX)contractor assignment even though we have the delete and create methods defined in the interface but we don't really have to implement them as those function are not used on the GUI is that right so whether to write the codes and implement those function is up to us am I correct ? but not necessary have to
any explanationo would be appreciated
thanks
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Hi Billy,
Initially I also did not plan to implement create / delete (just throw operationnotsupported exception); however if you have your update method, the create and delete methods can be implemented within half an hour...
I implemented them now, and it is very helpful for testing purposes. I'll probably leave them in...
Greetings,
TK
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
Hi
thanks for your insight
but is it a MUST to have fully working create and delete functionalities according to Sun's requirement?
is it okay to not have the create and delete methods written
if I dont do them am I still able to pass SCJD?
thanks
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Hi Billy,
To be honest: I am not sure anymore whether it is OK to leave them blank...
Maybe Max has an answer to this question...
TK
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
We're not really sure about this, but see this previous discussion (starting at the eleventh post or so, where I say "We're not?"). You may be able to pass without providing a working implementation of create() and delete() - but I'd expect you'd at least lose points for it. Why risk it?
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
I think you need to have them, but I don't think you need to provide access to them through the gui.
M


Java Regular Expressions
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
I'm pretty much done with the Contractor project.
My GUI client provides Search, update, delete, create, and set owner function. I personly do think that Create/Delete methods are required because those are the most basic function.
Nitti
S. Ganapathy
Ranch Hand

Joined: Mar 26, 2003
Posts: 194
Hi Nitti,
Contractor assignment requirement does not have delete functionality. Only search, and update(booking by providing owner field) only.
How did you provide search? search is only on name and location or on all fields?
Regards,
Ganapathy
Steven Wexelstein
Greenhorn

Joined: Jun 03, 2003
Posts: 1
Is adding the delete and create functionality in the GUI not out of the scope of the requirement. I think implementing it on the server side may well be okay but giving the user access without the requirment doesn't feel right.
S. Ganapathy
Ranch Hand

Joined: Mar 26, 2003
Posts: 194
ya, in GUI, there is no create/delete functionality.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
For that matter, the GUI is not required to (and probably should not) provide a general update function that allows users to change any field other than owner (customer ID). The only change of any type which the GUI is required to perform is to change the customer ID, to book a record (if it's not already booked by another customer). It may also be reasonable to provide cancel booking functionality (set a customer ID to blank), but this is not necessarily required. Judgement call; I'd include it.
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
I should read the requirement again, but I think the "users" are the customer representives, not customers themself. Customers call the representives, and the customer representives use client program to find a contractor for them.
This is my understanding of who is going to use the client program.
Since users are customer representives, I think they should be able to update or modify the data.
I will check out the requirement again.
Nitti
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Originally posted by S. Ganapathy:
How did you provide search? search is only on name and location or on all fields?

Hi Ganapathy,
I allow user to search by name, location, specialities, size, rate, and owner.
Nitti
S. Ganapathy
Ranch Hand

Joined: Mar 26, 2003
Posts: 194
Hi Nitti,
Thankyou very much. Me too provided search on all fields.
Regards,
Ganapathy.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Since users are customer representives, I think they should be able to update or modify the data.
Maybe - we can argue this either way. Many companies might mant to limit what people can do - maybe the CSRs have not been fully trained in how the data are to be formatted, e.g. what if they leave off the $ in the rate field, or use "and" where "&" is expected, or use capitalization incorrectly, or just can't spell very well. Power to edit/create/delete arbitrary fields may be intentionally reserved to trusted individuals who will use a different program. Or not. We're required to allow for editing of the customer ID field; any other updates are optional as fare as requirements are concerned.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
I would say that they're not even optional. The client has told you what they want. Thus, in your bid to prove to Sun that you're a professional grade developer, I would say that you should code to the specs rigorously. Thus, no failures, but no 'features'.
It could be argued that you don't really have the right make the client wait longer for the product, just because you want to give them things they didn't ask for .
M
Nitti Lin
Ranch Hand

Joined: May 15, 2003
Posts: 39
Hi Max,
Yeah, you got the point. I just worry too much. Should I remove create and delete function?
Thanks,
Nitti
[ June 05, 2003: Message edited by: Nitti Lin ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NX: (Contractors) File I/O class