Открыть пакет Debian с помощью Java - PullRequest
2 голосов
/ 15 сентября 2011

Есть ли в Java библиотеки для распаковки архива .deb (debian)? К сожалению, я пока не смог найти ничего полезного. Спасибо.

Ответы [ 2 ]

3 голосов
/ 15 сентября 2011

Если вы, распаковывая, хотите извлечь файлы, это должно быть возможно с Apache Commons Compress . Файл .deb « реализован как архивный архив », и Commons Compress может распаковывать архивные архивы.

1 голос
/ 26 сентября 2011

Хорошо, поэтому, как и предполагалось, я использовал сжатие Apache Commons и вот метод, который добивается цели. Загрузил его из репозитория 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;
}
...