簡體   English   中英

用Java打開Debian軟件包

[英]Open debian package with Java

Java中是否有用於解壓縮.deb(debian)歸檔文件的庫? 不幸的是,我找不到任何有用的東西。 謝謝。

如果通過解壓縮來解壓縮文件,則可以使用Apache Commons Compress進行壓縮 .deb文件被“ 實現為ar存檔 ”,並且Commons Compress能夠解壓縮ar存檔。

好的,正如我建議的那樣,我使用了apache commons compress,這是一種可以解決問題的方法。 從Maven存儲庫中將其縮編為: 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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM