From 2b24f6c1ce9ecbf05c647473ea7fe3f94cfaf892 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 7 Dec 2023 19:34:42 +0100 Subject: jgvariant-tool: Remove Guava dependency. This reduces the uberjar size from 4 MB to 1.2 MB. Change-Id: I06e202fe3c5e942511952f43b8f2c5941027cce9 --- .../eu/mulk/jgvariant/tool/jsonb/VariantSerializer.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'jgvariant-tool/src/main/java/eu') diff --git a/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/jsonb/VariantSerializer.java b/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/jsonb/VariantSerializer.java index 99ff553..311033c 100644 --- a/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/jsonb/VariantSerializer.java +++ b/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/jsonb/VariantSerializer.java @@ -4,13 +4,13 @@ package eu.mulk.jgvariant.tool.jsonb; -import com.google.common.primitives.Bytes; import eu.mulk.jgvariant.core.Signature; import eu.mulk.jgvariant.core.Variant; import jakarta.json.bind.serializer.JsonbSerializer; import jakarta.json.bind.serializer.SerializationContext; import jakarta.json.stream.JsonGenerator; import java.text.ParseException; +import java.util.Collection; import java.util.List; @SuppressWarnings("java:S6548") @@ -35,9 +35,18 @@ public final class VariantSerializer implements JsonbSerializer { @SuppressWarnings("unchecked") public void serialize(Variant obj, JsonGenerator generator, SerializationContext ctx) { if (obj.signature().equals(byteArraySignature)) { - byteArraySerializer.serialize(Bytes.toArray((List) obj.value()), generator, ctx); + byteArraySerializer.serialize(byteArrayOf((List) obj.value()), generator, ctx); } else { ctx.serialize(obj.value(), generator); } } + + private static byte[] byteArrayOf(Collection bytes) { + byte[] result = new byte[bytes.size()]; + int i = 0; + for (byte b : bytes) { + result[i++] = b; + } + return result; + } } -- cgit v1.2.3