Question about VfsUtil.findFileByUrl()

Hi,

I'm having serious trouble using VfsUtil.findFileByUrl().

The situation is as follows:

I have a VirtualFile instance. The URL for that file (obtained by VirtualFile.getUrl()
is written into my plugin configuration. When this URL is read back again, I try to get
an instance to a VirtualFile by calling VfsUtil.findFileByUrl(). But that always fails
and returns null. The URL looks correctly and the denoted file exists.

Now the interesting part: When using

VfsUtil.findFileByUrl(new File(somePath).toURL())

it works. So, what's the difference?

The only difference I noticed is, that the URL returned by VirtualFile.getUrl() looks like this:
file://C:/work/project/myFile.tld

Whereas the URL from File.toURL() looks like this
file:/C:/work/project/myFile.tld


It looks like the additional / confuses IDEA somehow. Since I don't think this is a bug
in IDEA (I guess a lot internal stuff depends on that) I think I've missed something in the
OpenAPI for dealing with URLs, VirtualFiles, etc.

Can someone point me into the right direction please?


Thanks,
Sascha


0
2 comments

You should use VirtualFileManager.findFileByUrl() method to find VirtualFile
by url obtained by VirtualFile.getUrl() method.
Method VfsUtil.findFileByUrl() is an utility method for finding VirtualFile
by java.net.URL (which has different format and is not compatible with VFS's
url).

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"Sascha Weinreuter" <sascha.weinreuter@cit.de> wrote in message
news:arj4gf$di8$1@is.intellij.net...

Hi,

>

I'm having serious trouble using VfsUtil.findFileByUrl().

>

The situation is as follows:

>

I have a VirtualFile instance. The URL for that file (obtained by

VirtualFile.getUrl()

is written into my plugin configuration. When this URL is read back again,

I try to get

an instance to a VirtualFile by calling VfsUtil.findFileByUrl(). But that

always fails

and returns null. The URL looks correctly and the denoted file exists.

>

Now the interesting part: When using

>

VfsUtil.findFileByUrl(new File(somePath).toURL())

>

it works. So, what's the difference?

>

The only difference I noticed is, that the URL returned by

VirtualFile.getUrl() looks like this:

file://C:/work/project/myFile.tld

>

Whereas the URL from File.toURL() looks like this
file:/C:/work/project/myFile.tld

>
>

It looks like the additional / confuses IDEA somehow. Since I don't think

this is a bug

in IDEA (I guess a lot internal stuff depends on that) I think I've missed

something in the

OpenAPI for dealing with URLs, VirtualFiles, etc.

>

Can someone point me into the right direction please?

>
>

Thanks,
Sascha

>
>


0


Thank you very much. I knew I missed something.
Now it works like a charm.

Sascha


Valentin Kipiatkov wrote:

You should use VirtualFileManager.findFileByUrl() method to find VirtualFile
by url obtained by VirtualFile.getUrl() method.
Method VfsUtil.findFileByUrl() is an utility method for finding VirtualFile
by java.net.URL (which has different format and is not compatible with VFS's
url).

>

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"

>
>

"Sascha Weinreuter" <sascha.weinreuter@cit.de> wrote in message
news:arj4gf$di8$1@is.intellij.net...

Hi,

>

I'm having serious trouble using VfsUtil.findFileByUrl().

>

The situation is as follows:

>

I have a VirtualFile instance. The URL for that file (obtained by

VirtualFile.getUrl()

is written into my plugin configuration. When this URL is read back again,

I try to get

an instance to a VirtualFile by calling VfsUtil.findFileByUrl(). But that

always fails

and returns null. The URL looks correctly and the denoted file exists.

>

Now the interesting part: When using

>

VfsUtil.findFileByUrl(new File(somePath).toURL())

>

it works. So, what's the difference?

>

The only difference I noticed is, that the URL returned by

VirtualFile.getUrl() looks like this:

file://C:/work/project/myFile.tld

>

Whereas the URL from File.toURL() looks like this
file:/C:/work/project/myFile.tld

>
>

It looks like the additional / confuses IDEA somehow. Since I don't think

this is a bug

in IDEA (I guess a lot internal stuff depends on that) I think I've missed

something in the

OpenAPI for dealing with URLs, VirtualFiles, etc.

>

Can someone point me into the right direction please?

>
>

Thanks,
Sascha

>
>

>
>


0

Please sign in to leave a comment.