diff --git a/gradle.properties b/gradle.properties index 42657a6f1..0183477bd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # Warning, "version" should be the same in gradle.properties and Version.java # Any idea anyone how to magically synchronize those :-) ? -version = 1.2024.2 +version = 1.2024.3beta1 org.gradle.workers.max = 3 \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/code/CompressionGZip.java b/src/net/sourceforge/plantuml/code/CompressionGZip.java new file mode 100644 index 000000000..0f87d56ef --- /dev/null +++ b/src/net/sourceforge/plantuml/code/CompressionGZip.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://plantuml.com/paypal + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Original Author: Arnaud Roques + * + * + */ +package net.sourceforge.plantuml.code; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.GZIPInputStream; + +public class CompressionGZip implements Compression { + // ::remove file when __CORE__ + + public byte[] compress(byte[] in) { + throw new UnsupportedOperationException(); + } + + public ByteArray decompress(byte[] input) throws NoPlantumlCompressionException { + try { + try (final GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(input))) { + final byte[] buffer = new byte[10_000]; + + try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + int len; + while ((len = gzip.read(buffer)) > 0) { + baos.write(buffer, 0, len); + if (baos.size() > 200_000) + throw new NoPlantumlCompressionException("Gzip error"); + } + return ByteArray.from(baos.toByteArray()); + } + } + } catch (IOException e) { + throw new NoPlantumlCompressionException(e); + } + + } + +} diff --git a/src/net/sourceforge/plantuml/code/TranscoderSmart.java b/src/net/sourceforge/plantuml/code/TranscoderSmart.java index 072bbd27c..dbf5a2bb2 100644 --- a/src/net/sourceforge/plantuml/code/TranscoderSmart.java +++ b/src/net/sourceforge/plantuml/code/TranscoderSmart.java @@ -49,6 +49,8 @@ public class TranscoderSmart implements Transcoder { new CompressionHuffman()); private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(), new CompressionZip()); + private final Transcoder gzip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(), + new CompressionGZip()); // ::done public String decode(String code) throws NoPlantumlCompressionException { @@ -66,6 +68,9 @@ public class TranscoderSmart implements Transcoder { if (code.startsWith("~h")) return hexOnly.decode(code.substring(2)); + if (code.startsWith("~g")) + return gzip.decode(code.substring(2)); + // ::comment when __CORE__ if (code.startsWith("~zip~")) return zip.decode(code.substring(5)); diff --git a/src/net/sourceforge/plantuml/code/TranscoderSmartProtected.java b/src/net/sourceforge/plantuml/code/TranscoderSmartProtected.java index f0b2dc7ca..61aefd6df 100644 --- a/src/net/sourceforge/plantuml/code/TranscoderSmartProtected.java +++ b/src/net/sourceforge/plantuml/code/TranscoderSmartProtected.java @@ -49,6 +49,8 @@ public class TranscoderSmartProtected implements Transcoder { new CompressionNone()); private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(), new CompressionZip()); + private final Transcoder gzip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(), + new CompressionGZip()); public String decode(String code) throws NoPlantumlCompressionException { // Work in progress @@ -63,6 +65,9 @@ public class TranscoderSmartProtected implements Transcoder { if (code.startsWith("~h")) return hexOnly.decode(code.substring(2)); + if (code.startsWith("~g")) + return gzip.decode(code.substring(2)); + if (code.startsWith("~zip~")) return zip.decode(code.substring(5)); diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index c4fd81c82..9919c1db5 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -46,7 +46,7 @@ public class Version { // Warning, "version" should be the same in gradle.properties and Version.java // Any idea anyone how to magically synchronize those :-) ? - private static final String version = "1.2024.2"; + private static final String version = "1.2024.3beta1"; public static String versionString() { return version;