Skip to content

Obtaining a URL from a jimfs Path #13

@skuzzle

Description

@skuzzle

A framework I'm testing internally needs to obtain an URL from a passed in path. For testing, I'd like to use jimfs, but obtaining a URL from a jimfs path seems not to be possible. Calling path.toUri().tourl("") throws a MalformedURLException with message: java.net.MalformedURLException: unknown protocol: jimfs. Is this something fixable or something to live with? Here is a simpe test case to reproduce:

import java.net.MalformedURLException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.Path;

import org.junit.Test;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;

public class JimFSTest {

    @Test
    public void testGetURL() throws MalformedURLException {
        final FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
        final Path path = fs.getPath("foo", "bar");
        final URI uri = path.toUri();
        uri.toURL();
    }
}

Edit: I just found out that one can implement a URLStreamHandlerFactory to accomplish this. You might consider to ship a suitable implementation for jimfs.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions