net.sourceforge.plantuml.code.TranscoderSmart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.code;
import java.io.IOException;
public class TranscoderSmart implements Transcoder {
private final Transcoder zlib = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
new CompressionZlib());
private final Transcoder hexOnly = TranscoderImpl.utf8(new AsciiEncoderHex(), new ArobaseStringCompressor(),
new CompressionNone());
// ::comment when __CORE__
// Legacy encoder
private final Transcoder oldOne = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
new CompressionHuffman());
private final Transcoder zip = TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(),
new CompressionZip());
public String decode(String code) throws NoPlantumlCompressionException {
// Work in progress
// See https://github.com/plantuml/plantuml/issues/117
if (code.startsWith("~0"))
return zlib.decode(code.substring(2));
// ::comment when __CORE__
if (code.startsWith("~1"))
return oldOne.decode(code.substring(2));
if (code.startsWith("~h"))
return hexOnly.decode(code.substring(2));
// ::comment when __CORE__
if (code.startsWith("~zip~"))
return zip.decode(code.substring(5));
// ::comment when __CORE__
try {
return zlib.decode(code);
// ::comment when __CORE__
} catch (Exception ex) {
return oldOne.decode(code);
}
// return zlib.decode(code);
}
public String encode(String text) throws IOException {
// Right now, we still use the legacy encoding.
// This will be changed in the incoming months
return zlib.encode(text);
}
}