Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read content of an RPM in java

Tags:

java

rpm

I'm looking for a way to read an RPM's content in java runtime.

Someone has suggested using 7zip to unpack and/or extract the RPM in runtime, using system command for 7zip.

that solution has two cons:

  1. It is platform dependent (since the commands will be specific to one OS)
  2. It involved third party software.

any ideas?

EDIT :
I'm trying to go down Robert's road. Here is my code:

String file = "MyRpm.rpm";

CpioArchiveInputStream cpioIn = 
       new CpioArchiveInputStream( new FileInputStream(new File(file)) );
 CpioArchiveEntry cpioEntry;



while ((cpioEntry = cpioIn.getNextEntry()) != null)
{
    System.out.println(cpioEntry.getName());
    int tmp;
    StringBuffer buf = new StringBuffer();
    while ((tmp = cpioIn.read()) != -1)
    {
        buf.append((char) tmp);
    }
    System.out.println(buf.toString());
}
cpioIn.close();

I'm getting an exception: java.io.IOException: Unknown magic [???? (The funny characters are from the original error message).

like image 209
summerbulb Avatar asked Nov 22 '11 09:11

summerbulb


People also ask

How do I extract files from an RPM package?

Examples – Extract files from rpm In this example, output of the rpm2cpio command piped to the cpio command with the following options: i : Restore archive. d : Create leading directories where needed. m : Retain previous file modification times when creating files.


1 Answers

It seems that commons-compress has a cpio package which you might find useful in reading the data from RPM files.

like image 80
Robert Munteanu Avatar answered Oct 20 '22 02:10

Robert Munteanu