简体   繁体   English

如何在java中阅读RPM的内容

[英]How to read content of an RPM in java

I'm looking for a way to read an RPM's content in java runtime. 我正在寻找一种在java运行时读取RPM内容的方法。

Someone has suggested using 7zip to unpack and/or extract the RPM in runtime, using system command for 7zip. 有人建议使用7zip在运行时解压缩和/或提取RPM,使用7zip的系统命令。

that solution has two cons: 该解决方案有两个缺点:

  1. It is platform dependent (since the commands will be specific to one OS) 它取决于平台(因为命令将特定于一个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 [???? 我得到一个异常: java.io.IOException: Unknown magic [???? (The funny characters are from the original error message). (有趣的字符来自原始错误消息)。

似乎commons-compress有一个cpio包 ,你可能会发现它在从RPM文件中读取数据时很有用。

使用库解压缩LZMA: http//www.7-zip.org/sdk.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM