This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S  public int[] find(String[] criteria) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S  public int[] find(String[] criteria)" Watch "B&S  public int[] find(String[] criteria)" New topic
Author

B&S public int[] find(String[] criteria)

efoe akolly
Greenhorn

Joined: Jun 11, 2003
Posts: 17
I am planning to use the StringTokenizer to parse my database but since I have a binary file I don't know on which tokens I should parse a given record. When you create a StringTokenizer object you need to specify the token(s) on which a string is supposed to be broken like :
StringTokenizer mainStringTokenizer =
new StringTokenizer(searchCriteria, ",");
In my case I really don't know what to do.
Any suggestion will be very much appreciated.
Thanks
Dieskun Koper
Ranch Hand

Joined: Aug 15, 2004
Posts: 85
The StringTokenizer is a utility class to break up a string
that uses delimiters to separate the tokens.
Your database file has "no separators between fields". Therefore,
StringTokenizer is not appropiate.
efoe akolly
Greenhorn

Joined: Jun 11, 2003
Posts: 17
Thank you for your reply. I really appreciated it. In your opinion what other alternative can I use then.
Thanks
Dieskun Koper
Ranch Hand

Joined: Aug 15, 2004
Posts: 85
I'll tell you what I did and why if you tell me what alternatives you are considering and why.
efoe akolly
Greenhorn

Joined: Jun 11, 2003
Posts: 17
Well I am thinking about using regular expression but that also requires a split delimiter so I don't know anymore.
Dieskun Koper
Ranch Hand

Joined: Aug 15, 2004
Posts: 85
I read the file using DataInputStream's readByte and readFully methods. First the schema, with a for loop over the fields, then the records.
For single byte values I used readByte, for fields of which the size is known (or read from the schema), I used readFully.

I am not sure if there is a more flexible way that is less vulnerable to schema changes, that is why I wanted to hear your alternatives

Regards,
Dies
efoe akolly
Greenhorn

Joined: Jun 11, 2003
Posts: 17
Thanks Koper.
dennis du
Ranch Hand

Joined: Dec 31, 2004
Posts: 59
I am behind you. I used the RandomAccessFile class for the binary file too.

And I think this is the only way to do it according the database file sun provided. If you want to make it flexible,then don't set the read length contant,it is ok.


-------------------------------<br />OCP 9i <br />SCJP/SCJD/SCWCD(92%)/SCDJWS<br />XML(IBM Test 141)<br />Who is the next?SCBCD<br />SCBCD/CCNA/CCNP/PMP<br />not sure
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: B&S public int[] find(String[] criteria)
 
Similar Threads
which would gives the greater performance ?whether StringTokenizer or split method of string
Conversion of string into an expression
Parsing
counting operaters from a text file
Tokens