--------------2F384FA98B5EEA51574AE3C4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Marco Lawrenz wrote:
> I'm converting an application from 3.5.1 to 4.0 using tops.exe. Now the
> occurences of
> ImmutableHashtable are now converted to NSDictionary.
>
> Unfortunately the constructor ImmutableHashtable(File aFile) has been
> vanished (after
> it NEVER appeared in 3.5.1- documentation) and wether NSDictionary
> (neither NSMutableDictionary)
> offers a constructor with such parameter.
>
> Does anybody have an idea how to convert this constructor resp.
> workaround it ?
I did something like this, most of it was in one of the examples
that came with WO 4.0. You could probably do it someway easier
than this if you looked into it.
public static NSDictionary getDictionaryFromFile (String
filenameWithPath) {
try {
filenameWithPath.replace('\\', '/'); // Fighting NT
File file = new File(filenameWithPath);
return (NSDictionary)objectFromPListFile(file);
} catch (Exception e) {
System.err.println("Cannot load dictionary from file" + e);
return null; // Return null, let them handle it there.
} // end try
} // end getDictionaryFromThisFile
public static Object objectFromPListFile(File file) throws IOException
{
return
NSPropertyListSerialization.propertyListFromString(stringFromFile(file));
}
public static String stringFromFile(File file) throws IOException {
if (file==null)
throw new IOException("null file");
int size=(int) file.length();
FileInputStream fis=new FileInputStream(file);
byte [] data = new byte[size];
int bytesRead=0;
while (bytesRead<size)
bytesRead+=fis.read(data,bytesRead,size-bytesRead);
fis.close();
return new String(data);
}
> BTW, the application I'm converting is the DodgeLiteJava demo
> application that came with WO 3.5.1. There is code used in the demos
> which was neither documented nor is taken it over. Reminds me of the
> "undocumented-Windows 3.1"-times.
>
> Thanks
>
> -- marco
>
> ------------------------------------------------
> Marco Lawrenz
> Condat GmbH Tel: +49-30-39094-208
> AltMoabit 91 d Fax: +49-30-39094-300
> 10559 Berlin mailto:[EMAIL PROTECTED]
> http://www.condat.de
> CONDAT auf der CeBIT: Halle 3, Stand C64
> ------------------------------------------------
--------------------------------------------
[EMAIL PROTECTED]
--------------2F384FA98B5EEA51574AE3C4
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<p>Marco Lawrenz wrote:
<blockquote TYPE=CITE>I'm converting an application from 3.5.1 to 4.0 using
tops.exe. Now the
<br>occurences of
<br>ImmutableHashtable are now converted to NSDictionary.
<p>Unfortunately the constructor ImmutableHashtable(File aFile) has been
<br>vanished (after
<br>it NEVER appeared in 3.5.1- documentation) and wether NSDictionary
<br>(neither NSMutableDictionary)
<br>offers a constructor with such parameter.
<p>Does anybody have an idea how to convert this constructor resp.
<br>workaround it ?</blockquote>
<tt><font size=+1></font></tt>
<p><br><tt><font size=+1>I did something like this, most of it was in one
of the examples</font></tt>
<br><tt><font size=+1>that came with WO 4.0. You could probably do
it someway easier</font></tt>
<br><tt><font size=+1>than this if you looked into it.</font></tt><tt><font
size=+1></font></tt>
<p><tt><font size=+1> public static NSDictionary
getDictionaryFromFile
(String filenameWithPath) {</font></tt>
<br><tt><font size=+1> try {</font></tt>
<br><tt><font
size=+1>
filenameWithPath.replace('\\', '/'); // Fighting NT</font></tt>
<br><tt><font
size=+1>
File file = new File(filenameWithPath);</font></tt>
<br><tt><font
size=+1>
return (NSDictionary)objectFromPListFile(file);</font></tt>
<br><tt><font size=+1> } catch
(Exception e) {</font></tt>
<br><tt><font
size=+1>
System.err.println("Cannot load dictionary from file" + e);</font></tt>
<br><tt><font
size=+1>
return null; // Return null, let them handle it there.</font></tt>
<br><tt><font size=+1> } // end
try</font></tt>
<br><tt><font size=+1> } // end
getDictionaryFromThisFile</font></tt><tt><font size=+1></font></tt>
<p><tt><font size=+1> public static Object objectFromPListFile(File
file) throws IOException {</font></tt>
<br><tt><font size=+1> return
NSPropertyListSerialization.propertyListFromString(stringFromFile(file));</font></tt>
<br><tt> }</tt><tt></tt>
<p><tt> public static String stringFromFile(File file)
throws IOException {</tt>
<br><tt> if (file==null)</tt>
<br><tt>
throw new IOException("null file");</tt>
<br><tt> int size=(int) file.length();</tt>
<br><tt> FileInputStream fis=new
FileInputStream(file);</tt>
<br><tt> byte [] data = new byte[size];</tt>
<br><tt> int bytesRead=0;</tt>
<br><tt> while (bytesRead<size)</tt>
<br><tt>
bytesRead+=fis.read(data,bytesRead,size-bytesRead);</tt>
<br><tt> fis.close();</tt>
<br><tt> return new String(data);</tt>
<br><tt> }</tt>
<blockquote TYPE=CITE>BTW, the application I'm converting is the DodgeLiteJava
demo
<br>application that came with WO 3.5.1. There is code used in the demos
<br>which was neither documented nor is taken it over. Reminds me of the
<br>"undocumented-Windows 3.1"-times.
<p>Thanks
<p>-- marco
<p>------------------------------------------------
<br>
Marco Lawrenz
<br>Condat
GmbH
Tel: +49-30-39094-208
<br>AltMoabit 91 d
Fax: +49-30-39094-300
<br>10559
Berlin
<a href="mailto:[EMAIL PROTECTED]">mailto:[EMAIL PROTECTED]</a>
<br> <a
href="http://www.condat.de">http://www.condat.de</a>
<br>CONDAT auf der CeBIT: Halle 3, Stand C64
<br>------------------------------------------------</blockquote>
--------------------------------------------
<br>[EMAIL PROTECTED]
<br> </html>
--------------2F384FA98B5EEA51574AE3C4--