.deb (debian) 아카이브의 압축을 풀기위한 Java 라이브러리가 있습니까? 불행히도 아직 유용한 정보가 없습니다. 감사.Java로 debian 패키지 열기
답변
압축을 해제하여 파일을 추출하는 경우 Apache Commons Compress으로 가능해야합니다. .deb 파일은 "implemented as an ar archive"이고 Commons Compress는 ar 아카이브를 압축 해제 할 수 있습니다.
감사합니다. 나는 확실히 Apache Commons Compress를 시도 할 것입니다 ... "ar 아카이브"부분을 알아 채지 못했습니다. –
최상위'ar' 아카이브는 차례로 두 개의'tar' 아카이브를 포함 할 것이지만, 분명히 ACC는 그에 대응해야합니다. – tripleee
좋습니다, 나는 아파치 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;
}
위의 소스 코드를 수정했습니다. "entry"변수는 디렉토리를 나타낼 수 있습니다. 이 경우 if (entry.isDirectory())를 추가하고 필요한 디렉토리를 만들 었는지 확인하십시오. –
아카이브를 열어 내용을 확인하거나 실제로 아카이브를 배포한다는 의미입니까? – Peter
사용자가 ".deb를 풀기 위해 ..."라고 썼습니다. 그래서 그는 아마도 추출을 의미합니다. – noamt
아카이브의 압축을 풀어 임시 폴더에 배포하려고합니다. 그래서 .deb 아카이브에 X/Y/Z가있는 파일/폴더가 있으면 임시 폴더에 X, Y, Z를 추출하고 "T"라고 말하면서 "새 파일 (T, X)"를 만들 수 있습니다. –