mirror of
https://github.com/octoleo/plantuml.git
synced 2024-06-01 08:00:48 +00:00
feat: adding undocumented support for gzip URL
This commit is contained in:
parent
cfa16d0f60
commit
ad4a1bde57
|
@ -1,4 +1,4 @@
|
||||||
# Warning, "version" should be the same in gradle.properties and Version.java
|
# Warning, "version" should be the same in gradle.properties and Version.java
|
||||||
# Any idea anyone how to magically synchronize those :-) ?
|
# Any idea anyone how to magically synchronize those :-) ?
|
||||||
version = 1.2024.2
|
version = 1.2024.3beta1
|
||||||
org.gradle.workers.max = 3
|
org.gradle.workers.max = 3
|
71
src/net/sourceforge/plantuml/code/CompressionGZip.java
Normal file
71
src/net/sourceforge/plantuml/code/CompressionGZip.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -49,6 +49,8 @@ public class TranscoderSmart implements Transcoder {
|
||||||
new CompressionHuffman());
|
new CompressionHuffman());
|
||||||
private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
|
private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
|
||||||
new CompressionZip());
|
new CompressionZip());
|
||||||
|
private final Transcoder gzip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
|
||||||
|
new CompressionGZip());
|
||||||
// ::done
|
// ::done
|
||||||
|
|
||||||
public String decode(String code) throws NoPlantumlCompressionException {
|
public String decode(String code) throws NoPlantumlCompressionException {
|
||||||
|
@ -66,6 +68,9 @@ public class TranscoderSmart implements Transcoder {
|
||||||
if (code.startsWith("~h"))
|
if (code.startsWith("~h"))
|
||||||
return hexOnly.decode(code.substring(2));
|
return hexOnly.decode(code.substring(2));
|
||||||
|
|
||||||
|
if (code.startsWith("~g"))
|
||||||
|
return gzip.decode(code.substring(2));
|
||||||
|
|
||||||
// ::comment when __CORE__
|
// ::comment when __CORE__
|
||||||
if (code.startsWith("~zip~"))
|
if (code.startsWith("~zip~"))
|
||||||
return zip.decode(code.substring(5));
|
return zip.decode(code.substring(5));
|
||||||
|
|
|
@ -49,6 +49,8 @@ public class TranscoderSmartProtected implements Transcoder {
|
||||||
new CompressionNone());
|
new CompressionNone());
|
||||||
private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
|
private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
|
||||||
new CompressionZip());
|
new CompressionZip());
|
||||||
|
private final Transcoder gzip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
|
||||||
|
new CompressionGZip());
|
||||||
|
|
||||||
public String decode(String code) throws NoPlantumlCompressionException {
|
public String decode(String code) throws NoPlantumlCompressionException {
|
||||||
// Work in progress
|
// Work in progress
|
||||||
|
@ -63,6 +65,9 @@ public class TranscoderSmartProtected implements Transcoder {
|
||||||
if (code.startsWith("~h"))
|
if (code.startsWith("~h"))
|
||||||
return hexOnly.decode(code.substring(2));
|
return hexOnly.decode(code.substring(2));
|
||||||
|
|
||||||
|
if (code.startsWith("~g"))
|
||||||
|
return gzip.decode(code.substring(2));
|
||||||
|
|
||||||
if (code.startsWith("~zip~"))
|
if (code.startsWith("~zip~"))
|
||||||
return zip.decode(code.substring(5));
|
return zip.decode(code.substring(5));
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class Version {
|
||||||
|
|
||||||
// Warning, "version" should be the same in gradle.properties and Version.java
|
// Warning, "version" should be the same in gradle.properties and Version.java
|
||||||
// Any idea anyone how to magically synchronize those :-) ?
|
// 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() {
|
public static String versionString() {
|
||||||
return version;
|
return version;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user