question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a means to convert a URI to a JimfsPath

See original GitHub issue

There is no obvious way to convert a URI into a JimfsPath. Normally, one could use fs.provider().getPath(uri), but this is not implemented by JimfsFileSystemProvider; instead, it throws an exception stating:

This method should not be called directly; use Paths.get(URI) instead.

Which is funny, since on #12 @cgdecker (main contributor to the project?)

strongly recommends not using Paths.get

I would’ve used JimfsFileSystem.toPath(URI), but the entire class is set to the package-private access modifier (why the hell?).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cgdeckercommented, Feb 24, 2020

@o2themar You’re getting that exception because you’re calling FileSystems.newFileSystem(URI, Map) with a URI with the scheme jimfs. That tells Jimfs to create a new Jimfs file system, not a zip file system, and the URI for a Jimfs file system isn’t allowed to have a path, query or fragment (because they don’t make sense in that context).

The scheme for a zip file system is jar:<underlying file system scheme>, so in the case of a file in a Jimfs file system, jar:jimfs. So your code would probably work if you just pass "jar:" + zipURI.getScheme() as the scheme for your new URI.

That said, you should be able to get a zip file system for a Jimfs path by just calling FileSystems.newFileSystem(Path, Map):

Path zipPath = pathFromJimfs;
Map<String, Object> env = new HashMap<>();
env.put("create", Boolean.toString(Files.notExists(outputZipAbsolutePath)));
env.put("encoding", "UTF-8");
FileSystem zipFileSystem = FileSystems.newFileSystem(zipPath, env);
0reactions
eyalrothcommented, Feb 20, 2020

@cgdecker I got to review this issue again with the recent activity, and I’m appalled at my previous behavior. I apologize for the demanding and combative tone. I really appreciate the work and effort you put into this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert file: Uri to File in Android - Stack Overflow
Uri object which is named uri and created exactly as in the question, uri.toString() returns a String in the format "file:///mnt/sdcard/myPicture.jpg" , whereas ......
Read more >
java.nio.file.Path.getFileSystem java code examples - Tabnine
This implementation creates a FileSystemResource, applying the given path * relative to the path of the underlying file of this resource descriptor.
Read more >
Java Examples for java.nio.file.ProviderMismatchException
This java examples will help you to understand the usage of java.nio.file.ProviderMismatchException. These source code samples are taken from different open ...
Read more >
TvInputInfo.java - Android Code Search
Search and explore code.
Read more >
Get File from URI - CommonsWare
I'm having a hard time getting a File's path from a URI. ... There are scenarios where that is needed (e.g., an import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found