On Feb 28, 2008, at 10:29 AM, Kedar Mhaswade wrote:
> Jerome Dochez wrote:
>> On Feb 28, 2008, at 12:15 AM, Kedar Mhaswade wrote:
>>>
>>>
>>> Jerome Dochez wrote:
>>>> Byron
>>>> 2 things :
>>>> - can you explain why using getCanonicalFile() is desired here. I
>>>> am not sure I see an advantage...
>>>
>>> This is mostly related to Windows.
>>>
>>> On Windows, a file created with File f = new File("c:/temp/foo");
>>>
>>> has canonical path returned as "C:/temp/foo" whereas
>>> absolute path returned as "c:/temp/foo"
>>>
>>> (Observe the case), when the drive was created as "C:".
>>>
>>> I guess Canonical path returns the correct system specific path.
>> I see but you cannot have a C: letter drive and a c: letter drive
>> on windows, right ?
>> is this problem theorical, I mean what kind of issues can we get
>> into by not using it ?
>
> No, it is neither purely academic, nor is it Windows specific.
>
> e.g. See the following snippet:
> -------------------------------
> import java.io.*;
>
> class Foo {
> public static void main(String ... args) throws Exception {
> File f = new File("../f");
> System.out.println(f.getCanonicalPath());
> System.out.println(f.getAbsolutePath());
> }
> }
> ------------------------------
>
> On my Mac OS X, this produces the following output:
>
> ------------------------------
> /Users/kedar/Projects/f
> /Users/kedar/Projects/Java/../f
> ------------------------------
>
> Now, though these are "equivalent", I think it's related to what
> the programmer wanted. Maybe the programmer thinks "absolutizing"
> means the former. I see no problems with that as long as the
> programmer is aware of the fact that getCanonicalPath() is going
> to result in slightly lower performance because it does some
> file system calls.
I see, thanks for the clarification.
Now didn't we have a bug in V1 or V2 with this getCanonical() type of
calls. I seem to remember some escalations because it was failing with
NFS mounted drive or something. I don't precisely remember but maybe
someone does ?
>
>
>
>>>
>>>
>>>> - you do not respect the Java Coding style... please do so
>>>
>>> I am sorry, but at least this code is highly readable ...
>>>
>> ok let's clear this up once for all. All employees of Sun
>> Microsystems and GlassFish code committers have to follow the
>> documented Java Coding style, we certainly have better things to do
>> than discuss which code is more beautiful or more readable.
>
> By that you mean following:
> http://java.sun.com/docs/codeconv ?
yes
so for instance
>>>>> + private File absolutize(File f)
>>>>> + {
>>>>> + try
>>>>> + {
>>>>> + return f.getCanonicalFile();
>>>>> + }
>>>>> + catch(Exception e)
>>>>> + {
>>>>> + return f.getAbsoluteFile();
>>>>> + }
>>>>> + }
should be :
>>>>> + private File absolutize(File f) {
>>>>> + try {
>>>>> + return f.getCanonicalFile();
>>>>> + } catch(Exception e) {
>>>>> + return f.getAbsoluteFile();
>>>>> + }
>>>>> + }
and there is more to the conventions of course.
Jerome
>
>
>> Jerome
>>>> thanks, Jerome
>>>> On Feb 27, 2008, at 1:24 AM, bnevins_at_dev.java.net wrote:
>>>>> + private File absolutize(File f)
>>>>> + {
>>>>> + try
>>>>> + {
>>>>> + return f.getCanonicalFile();
>>>>> + }
>>>>> + catch(Exception e)
>>>>> + {
>>>>> + return f.getAbsoluteFile();
>>>>> + }
>>>>> + }
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>