From 50a626db95a56160d8d08a6d0a6bb678b08b78d1 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 30 Dec 2021 19:13:49 +0100 Subject: jgvariant-ostree: DeltaPartPayload: Decompress LZMA if needed. Change-Id: I4a751b7778c30d2e126a058c766edaef7b641415 --- jgvariant-ostree/pom.xml | 6 ++++++ .../eu/mulk/jgvariant/ostree/DeltaPartPayload.java | 25 +++++++++++++++++++--- jgvariant-ostree/src/main/java/module-info.java | 3 ++- jgvariant-parent/pom.xml | 8 +++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/jgvariant-ostree/pom.xml b/jgvariant-ostree/pom.xml index 897efa9..6d67bde 100644 --- a/jgvariant-ostree/pom.xml +++ b/jgvariant-ostree/pom.xml @@ -47,6 +47,12 @@ apiguardian-api + + + org.tukaani + xz + + org.junit.jupiter diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java index 99e093d..ed0f4ff 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java @@ -1,9 +1,14 @@ package eu.mulk.jgvariant.ostree; import eu.mulk.jgvariant.core.Decoder; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.List; +import org.tukaani.xz.XZInputStream; /** * A payload file from a static delta. @@ -37,10 +42,24 @@ public record DeltaPartPayload( private static ByteBuffer preparse(ByteBuffer byteBuffer) { byte compressionByte = byteBuffer.get(0); + var dataSlice = byteBuffer.slice(1, byteBuffer.limit() - 1); return switch (compressionByte) { - case 0 -> byteBuffer.slice(1, byteBuffer.limit()); - case (byte) 'x' -> throw new UnsupportedOperationException( - "LZMA compression of static deltas is unsupported"); + case 0 -> dataSlice; + case (byte) 'x' -> { + try { + var dataBytes = new byte[dataSlice.limit()]; + dataSlice.get(dataBytes); + var decompressingInputStream = new XZInputStream(new ByteArrayInputStream(dataBytes)); + + var decompressedOutputStream = new ByteArrayOutputStream(); + decompressingInputStream.transferTo(decompressedOutputStream); + + yield ByteBuffer.wrap(decompressedOutputStream.toByteArray()); + } catch (IOException e) { + // impossible + throw new UncheckedIOException(e); + } + } default -> throw new IllegalArgumentException( "unrecognized compression byte '%d'".formatted(compressionByte)); }; diff --git a/jgvariant-ostree/src/main/java/module-info.java b/jgvariant-ostree/src/main/java/module-info.java index 59b458f..da86412 100644 --- a/jgvariant-ostree/src/main/java/module-info.java +++ b/jgvariant-ostree/src/main/java/module-info.java @@ -77,8 +77,9 @@ module eu.mulk.jgvariant.ostree { requires transitive eu.mulk.jgvariant.core; requires com.google.errorprone.annotations; - requires org.jetbrains.annotations; requires org.apiguardian.api; + requires org.jetbrains.annotations; + requires org.tukaani.xz; exports eu.mulk.jgvariant.ostree; } diff --git a/jgvariant-parent/pom.xml b/jgvariant-parent/pom.xml index d209863..a5b330f 100644 --- a/jgvariant-parent/pom.xml +++ b/jgvariant-parent/pom.xml @@ -66,6 +66,7 @@ 0.3.0 22.0.0 5.8.2 + 1.9 @@ -94,6 +95,13 @@ ${apiguardian.version} + + + org.tukaani + xz + 1.9 + + org.junit.jupiter -- cgit v1.2.3