Java 中是否有用于解压缩 .deb (debian) 存档的库?不幸的是,我还没有找到任何有用的东西。谢谢。
问问题
1084 次
2 回答
3
如果您通过解压来提取文件,那么应该可以使用Apache Commons Compress。.deb 文件被“实现为 ar 档案”,Commons Compress 能够解压缩 ar 档案。
于 2011-09-15T14:48:15.753 回答
1
好的,所以正如我所建议的那样,我使用了 apache commons compress,这是一种可以解决问题的方法。从 maven repo 下载它:http: //mvnrepository.com/artifact/org.apache.commons/commons-compress/1.2。
/**
* Unpack a deb archive provided as an input file, to an output directory.
* <p>
*
* @param inputDeb the input deb file.
* @param outputDir the output directory.
* @throws IOException
* @throws ArchiveException
*
* @returns A {@link List} of all the unpacked files.
*
*/
private static List<File> unpack(final File inputDeb, final File outputDir) throws IOException, ArchiveException {
LOG.info(String.format("Unzipping deb file %s.", deb.getAbsoluteFile()));
LOG.info(String.format("Into dir %s.", outDir.getAbsoluteFile()));
final List<File> unpackedFiles = new LinkedList<File>();
final InputStream is = new FileInputStream(inputDeb);
final ArArchiveInputStream debInputStream = (ArArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("ar", is);
ArArchiveEntry entry = null;
while ((entry = (ArArchiveEntry)debInputStream.getNextEntry()) != null) {
LOG.info("Read entry");
final File outputFile = new File(outputDir, entry.getName());
final OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(debInputStream, outputFileStream);
outputFileStream.close();
unpackedFiles.add(outputFile);
}
debInputStream.close();
return unpackedFiles;
}
于 2011-09-26T09:45:30.697 回答