In order to work with Jaxb, I need to have a normal java.io.File
Object. As I do not want to have legacy code in a quite new project, I want to use java.nio.file.Path
objects.
As gradle resolves dependencies in jar
files, I need to handle them as com.sun.nio.zipfs.ZipPath
. Now the thing is, that I am using these files only for codegeneration, and do not necessarily want to unpack them.
Unfortunately, the ZipPath.toFile()
method throws an UnsupportedOperationException
, so I cannot convert the Path to a File, which is necessary in order to use the JaxbUnmarshaller
, to validate the correct layout of the file and to convert it into an actual runtime object.
I tried:
How can I get a File from a ZipPath without unzipping it?
I suppose it is possible via the ZipFileSystem, but I dont get it.
It's not lovely but I recently solved this problem like so:
InputStream is = Files.newInputStream(zipPath);
final File tempFile = File.createTempFile("PREFIX", "SUFFIX");
tempFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(tempFile))
{
IOUtils.copy(in, out);
}
// do something with tempFile