Skip to content

Commit 364eec6

Browse files
committed
feat: added support for .tar.xz archives in ArchiveUtils
1 parent bb62717 commit 364eec6

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/main/java/dev/jbang/jdkdb/util/ArchiveUtils.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.zip.ZipFile;
1010
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
1111
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
12+
import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
1415

@@ -30,11 +31,12 @@ private ArchiveUtils() {
3031
*/
3132
public static Map<String, String> extractReleaseInfo(Path archiveFile, String filename) throws IOException {
3233
String lowerFilename = filename.toLowerCase();
33-
3434
if (lowerFilename.endsWith(".zip")) {
3535
return extractReleaseFromZip(archiveFile);
3636
} else if (lowerFilename.endsWith(".tar.gz") || lowerFilename.endsWith(".tgz")) {
3737
return extractReleaseFromTarGz(archiveFile);
38+
} else if (lowerFilename.endsWith(".tar.xz") || lowerFilename.endsWith(".txz")) {
39+
return extractReleaseFromTarGz(archiveFile);
3840
} else if (lowerFilename.endsWith(".pkg")) {
3941
// PKG extraction only supported on macOS using pkgutil
4042
if (isMacOS()) {
@@ -85,17 +87,19 @@ private static Map<String, String> extractReleaseFromZip(Path zipFile) throws IO
8587
}
8688

8789
/**
88-
* Extract release file from TAR.GZ archive.
90+
* Extract release file from TAR.GZ or TAR.XZ archive.
8991
*
90-
* @param tarGzFile The TAR.GZ file
92+
* @param tarFile The TAR.GZ or TAR.XZ file
9193
* @return Map of release properties or null if not found
9294
*/
93-
private static Map<String, String> extractReleaseFromTarGz(Path tarGzFile) throws IOException {
95+
private static Map<String, String> extractReleaseFromTarGz(Path tarFile) throws IOException {
9496
// Search for any file named "release" in the archive
9597
// This handles various layouts including macOS packages with nested structures
96-
try (InputStream fis = Files.newInputStream(tarGzFile);
97-
GZIPInputStream gzis = new GZIPInputStream(fis);
98-
TarArchiveInputStream tis = new TarArchiveInputStream(gzis)) {
98+
boolean isXz = tarFile.toString().toLowerCase().endsWith(".tar.xz")
99+
|| tarFile.toString().toLowerCase().endsWith(".txz");
100+
try (InputStream fis = Files.newInputStream(tarFile);
101+
InputStream compressedStream = isXz ? new XZCompressorInputStream(fis) : new GZIPInputStream(fis);
102+
TarArchiveInputStream tis = new TarArchiveInputStream(compressedStream)) {
99103

100104
TarArchiveEntry entry;
101105
while ((entry = tis.getNextEntry()) != null) {

0 commit comments

Comments
 (0)