2

.deb(debian)アーカイブを解凍するためのJavaのライブラリはありますか?残念ながら、私はまだそこに役立つものを見つけることができませんでした。ありがとう。

4

2 に答える 2

3

ファイルを解凍することを意味する場合は、Apache Commons Compressで可能です。.deb ファイルは「ar アーカイブとして実装」されており、Commons Compress は ar アーカイブを解凍できます。

于 2011-09-15T14:48:15.753 に答える
1

さて、提案したように、私は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;
}
于 2011-09-26T09:45:30.697 に答える