• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply. I really appreciated it. In your opinion what other alternative can I use then.
Thanks
 
Dieskun Koper
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll tell you what I did and why if you tell me what alternatives you are considering and why.
 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Koper.
 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!