Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AsynchronousFileChannel for a file in a jar

Is there a way to open an AsynchronousFileChannel for a file stored in a jar on the classpath?

If I try creating a Path directly, I get FileSystemNotFoundException. If I create the file system first:

URI uri = ...; //get the URI of a file in a jar
String[] array = uri.toString().split("!");
FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), Collections.emptyMap());
Path path = fs.getPath(array[1]);
AsynchronousFileChannel ch = AsynchronousFileChannel.open(path);

It explodes with UnsupportedOperationException :(

Is there any way to achieve this?

My project is Spring (and using ClassPathResource for this), so a Spring specific solution works.

like image 643
kaqqao Avatar asked Sep 02 '25 10:09

kaqqao


1 Answers

The zip file system provider in the JDK does not support asynchronous I/O so this is why UOE is throw.

like image 159
Alan Bateman Avatar answered Sep 03 '25 22:09

Alan Bateman