aspose file tools*
The moose likes Java in General and the fly likes Modified java.util.Properties class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Modified java.util.Properties class" Watch "Modified java.util.Properties class" New topic
Author

Modified java.util.Properties class

Nick Kocher
Greenhorn

Joined: Nov 24, 2004
Posts: 14
I need something like java.util.Properties class, where the store() method writes 2 extra lines at the beginning of the file and the load() method reads this two lines and makes something with them. Should I extend the Properties class and override the load() and store() methods? how would then the code in this methods look like aproximately?(Is it possible at all to find the code for the classes of API?) Or is it better to create a new class with a HashTable() object and use the java.io.* package?
Thank you for any help!
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

hi,

you could extend the Properties class, and over ride the store and load methods...you can use the "super()" to automatically duplicate what the superClass method is doing...so you can over ride the method. add your lines to the output stream and then call super().

I dont think you need the source code, but it is freely available the the JDK download I think.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You might find it cleaner to create a new class that has an instance of Properties. Your methods might look like:

This looks like more work because you have to provide a bunch of methods that do nothing but call the Properties instance, but there are some subtle dangers in extending any concrete class. Even though Properties is likely to be very stable over tme, this "decorator" is safer in the long run.

Of course a quick look at the doc shows Sun already stepped up to the dangers by extending HashMap. It's their problem to assure that future changes to HashMap don't break Properties. Don't join them in the risk if you can help it.


[ December 04, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Nick Kocher
Greenhorn

Joined: Nov 24, 2004
Posts: 14
Hi, thank you all!

the solution suggested here is exactly what I need!

I didn't understand about the source code to API classes, is it somewhere in JDK???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modified java.util.Properties class