Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid Data Files

 
Chris Bicnal
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

What have you guys done about validating the data file selected by the user to ensure it's a valid database?

Do you do it? If so, how does your GUI/Server react if it's invalid? How do you check to see if it's valid?

Thanks,

Chris
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my assignment, there is "magic cookie" to determine if it is a valid file or not.

To prevent user from selecting invalid database file, use the FileFilter. If the user is too stubborn and open the invalid file on purpose, just show the JOptionPane and don't open the file, let the user select the correct file.

Jeffry Kristianto Yanuar
SCJP 5.0
SCJA
SCJD (Working on UrlyBird 1.3.2)
 
Ewan Livingstone
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing that I think is worth doing is attempting to read all content from the file up front, when the user has selected the file. Wrap a big catch statement around your logic that parses the file; if an exception is thrown while trying to read the file, the file is invalid, and you should present an error to the user and make them choose a different file.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

My spec requires me to read the db schema in particular order. Based on the order of the schema, I have read magic cookie and other stuff. This magic cookie is used for identifying the correct db file. If magic cookie value is matched, I will read the file. If magic cookie value is not matched, I will throw a custom message to the user and ask him to select a valid file.

I have written a simple pseudo code to carry out the db reading.



or you can use conventional if else
 
Chris Bicnal
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I too have a 4 byte magic cookie value at the start of the file.

I think I'm going to read those four bytes first to compare them with the value in the file provided by Sun. If they match then I'll assume the file is valid, otherwise I'll reject it.

I guess this decision probably needs mentioning in the choices.txt file too.

Anyway guys, thanks for your help!

Chris
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also using the magic cookie value for validation purposes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic