geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Blewitt <>
Subject Re: [core] Directories w/spaces
Date Tue, 26 Aug 2003 14:32:51 GMT
How are you running it against File? Java 1.4 has a constructor that 
takes a URI, but no constructor that takes a URL.

Are you using the URL.toString() to obtain a file reference?

I have created a URI based on 'file:///tmp/here%20there' and it works 
as expected when accessing a file. Printing it out unencodes it, but 
passing the URI in its entirety to a File constructor allows the file 
to be accessed seamlessly.

public class Test {
   public static void main(String args[]) throws Exception {
     String u = args[0];
     System.out.println("\"" + u + "\"");
     System.out.println(new URI(u));
     System.out.println(new File(new URI(u)));
     System.out.println(new File(new URI(u)).lastModified());

java Test "file:///tmp/here%20there"

It would seem that all you need to do is replace URL with URI, and 
ensure that the argument to URI is encoded. You will note that running 
it with java Test "file:///tmp/here there" results in an 

String configFromSomewhere = ....
File file = new File(new URI(URLEncoder(configFromSomewhere));

works fine with spaces.


On Tuesday, Aug 26, 2003, at 15:17 Europe/London, Jason Dillon wrote:

> A URLEncoded string will cause URL() to puke.  And probably won't work 
> with File() either.
> --jason
> On Tuesday, August 26, 2003, at 09:12  PM, Daniel S. Haischt wrote:
>> just as a starting point (don't know whether it helps or not, tho).
>> what about:
>> String test1 =
>>   "file:///Program Files/MyProgram/test.txt", "UTF-8");
>> String test2 =
>>   test1, "UTF-8");
>> System.out.println(test1 + "\n" + test2);
>> it would decode/encode your strings which are containing
>> whitespaces.
>> regards
>> daniel s. haischt
>> --
>> James Strachan wrote:
>>> On Tuesday, August 26, 2003, at 02:37  pm, Alex Blewitt wrote:
>>>> On Tuesday, Aug 26, 2003, at 13:49 Europe/London, Jason Dillon 
>>>> wrote:
>>>>> Looks like the deployment system is not very happy with 
>>>>> directories with spaces in the path.  I looked into this some but 
>>>>> I am stumped with how to fix this right now.
>>>>> URI does not like a space in its spec, but URL is just fine with 
>>>>> this.  ServiceDeploymentPlanner is taking its DeployURL and 
>>>>> turning it into a URI, which fails if the URL has a space.
>>>>> I tried a few hacks to get around this, but then other bits of the 
>>>>> system fail from the space in the URL too.
>>>>> Is there a global solution to this problem, so we can translate a 
>>>>> urlspec into a URL which will also work for a URI and not break 
>>>>> reading content from file URLs too?
>>>> URI spaces should be escaped into %20 IIRC. So 'new URI("Hello 
>>>> World")' may fail, while 'new URI("Hello%20World")' may work. Of 
>>>> course, it then depends on the URI being properly unencoded at the 
>>>> other end where required.
>>> Thats a HTTP thing isn't it? Doesn't work for file based URIs AFAIK.
>>> James
>>> -------

View raw message