Reputation: 113
I want to extract a rpm file to target directory from Java code. I'm aware of the following approaches:
rpm2cpio mypackage.rpm | (cd /target/dir; cpio -idmv)
as command line. This is not really Java and I worry the portability by hardcoding this command.CpioArchiveInputStream
. I hit java.io.IOException: Unknown magic
when trying to read the rpm file. My guess is that this library is too old to adapt to new archive/compression types.Is there a better approach that I'm not aware of? Ideally something that works like a TarArchiveInputStream
would be perfect.
Upvotes: 1
Views: 604
Reputation: 416
Yes. An alternative using pure java is as follows:
Upvotes: 0
Reputation: 113
This is the middle ground that I found working:
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(String.format("rpm2cpio %s", packagePath));
try (CpioArchiveInputStream cpioStream = new CpioArchiveInputStream(proc.getInputStream())) {
System.out.println(cpioStream.getNextCPIOEntry().getName());
}
Not perfect, but makes it easier so that we only rely on a new process to read file.
Upvotes: 2