1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-23 03:19:06 +00:00

Use UTF_8 object instead of "UTF-8" string literal.

This commit is contained in:
matthew16550 2021-09-13 15:18:15 +10:00
parent 91749a2da3
commit e3e2c2836e
34 changed files with 131 additions and 62 deletions

View File

@ -35,6 +35,7 @@
*/ */
package net.sourceforge.plantuml; package net.sourceforge.plantuml;
import static java.nio.charset.StandardCharsets.UTF_8;
import static net.sourceforge.plantuml.utils.CharsetUtils.charsetOrDefault; import static net.sourceforge.plantuml.utils.CharsetUtils.charsetOrDefault;
import java.io.IOException; import java.io.IOException;
@ -186,7 +187,7 @@ public class BlockUml {
final AsciiEncoder coder = new AsciiEncoder(); final AsciiEncoder coder = new AsciiEncoder();
final MessageDigest msgDigest = MessageDigest.getInstance("MD5"); final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
for (StringLocated s : data) { for (StringLocated s : data) {
msgDigest.update(s.getString().getBytes("UTF-8")); msgDigest.update(s.getString().getBytes(UTF_8));
} }
final byte[] digest = msgDigest.digest(); final byte[] digest = msgDigest.digest();
return coder.encode(digest); return coder.encode(digest);

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml; package net.sourceforge.plantuml;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -77,7 +79,7 @@ public class Pipe {
for(String source = readFirstDiagram(); source != null; source = readSubsequentDiagram()) { for(String source = readFirstDiagram(); source != null; source = readSubsequentDiagram()) {
final Defines defines = option.getDefaultDefines(); final Defines defines = option.getDefaultDefines();
final SFile newCurrentDir = option.getFileDir() == null ? null : new SFile(option.getFileDir()); final SFile newCurrentDir = option.getFileDir() == null ? null : new SFile(option.getFileDir());
final SourceStringReader sourceStringReader = new SourceStringReader(defines, source, "UTF-8", final SourceStringReader sourceStringReader = new SourceStringReader(defines, source, UTF_8,
option.getConfig(), newCurrentDir); option.getConfig(), newCurrentDir);
if (option.isComputeurl()) { if (option.isComputeurl()) {

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml; package net.sourceforge.plantuml;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -127,12 +129,12 @@ public class SignatureUtils {
public static synchronized byte[] getMD5raw(String s) public static synchronized byte[] getMD5raw(String s)
throws NoSuchAlgorithmException, UnsupportedEncodingException { throws NoSuchAlgorithmException, UnsupportedEncodingException {
final MessageDigest msgDigest = MessageDigest.getInstance("MD5"); final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
msgDigest.update(s.getBytes("UTF-8")); msgDigest.update(s.getBytes(UTF_8));
return msgDigest.digest(); return msgDigest.digest();
} }
public static byte[] getSHA512raw(String s) throws NoSuchAlgorithmException, UnsupportedEncodingException { public static byte[] getSHA512raw(String s) throws NoSuchAlgorithmException, UnsupportedEncodingException {
return getSHA512raw(s.getBytes("UTF-8")); return getSHA512raw(s.getBytes(UTF_8));
} }
public static synchronized byte[] getSHA512raw(byte data[]) public static synchronized byte[] getSHA512raw(byte data[])

View File

@ -35,12 +35,14 @@
*/ */
package net.sourceforge.plantuml; package net.sourceforge.plantuml;
import static java.nio.charset.StandardCharsets.UTF_8;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.plainImageBuilder; import static net.sourceforge.plantuml.ugraphic.ImageBuilder.plainImageBuilder;
import static net.sourceforge.plantuml.utils.CharsetUtils.charsetOrDefault; import static net.sourceforge.plantuml.utils.CharsetUtils.charsetOrDefault;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.StringReader; import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -62,31 +64,39 @@ public class SourceStringReader {
} }
public SourceStringReader(String source, String charset) { public SourceStringReader(String source, String charset) {
this(Defines.createEmpty(), source, "UTF-8", Collections.<String>emptyList()); this(Defines.createEmpty(), source, UTF_8.name(), Collections.<String>emptyList());
}
public SourceStringReader(String source, Charset charset) {
this(Defines.createEmpty(), source, charset.name(), Collections.<String>emptyList());
} }
public SourceStringReader(Defines defines, String source, List<String> config) { public SourceStringReader(Defines defines, String source, List<String> config) {
this(defines, source, "UTF-8", config); this(defines, source, UTF_8.name(), config);
} }
public SourceStringReader(Defines defines, String source) { public SourceStringReader(Defines defines, String source) {
this(defines, source, "UTF-8", Collections.<String>emptyList()); this(defines, source, UTF_8.name(), Collections.<String>emptyList());
} }
public SourceStringReader(String source, SFile newCurrentDir) { public SourceStringReader(String source, SFile newCurrentDir) {
this(Defines.createEmpty(), source, "UTF-8", Collections.<String>emptyList(), newCurrentDir); this(Defines.createEmpty(), source, UTF_8, Collections.<String>emptyList(), newCurrentDir);
} }
public SourceStringReader(Defines defines, String source, String charset, List<String> config) { public SourceStringReader(Defines defines, String source, String charset, List<String> config) {
this(defines, source, charset, config, FileSystem.getInstance().getCurrentDir()); this(defines, source, charset, config, FileSystem.getInstance().getCurrentDir());
} }
public SourceStringReader(Defines defines, String source, String charset, List<String> config, public SourceStringReader(Defines defines, String source, String charset, List<String> config, SFile newCurrentDir) {
this(defines, source, charsetOrDefault(charset), config, newCurrentDir);
}
public SourceStringReader(Defines defines, String source, Charset charset, List<String> config,
SFile newCurrentDir) { SFile newCurrentDir) {
// // WARNING GLOBAL LOCK HERE // // WARNING GLOBAL LOCK HERE
// synchronized (SourceStringReader.class) { // synchronized (SourceStringReader.class) {
try { try {
final BlockUmlBuilder builder = new BlockUmlBuilder(config, charsetOrDefault(charset), defines, new StringReader(source), final BlockUmlBuilder builder = new BlockUmlBuilder(config, charset, defines, new StringReader(source),
newCurrentDir, "string"); newCurrentDir, "string");
this.blocks = builder.getBlockUmls(); this.blocks = builder.getBlockUmls();
} catch (IOException e) { } catch (IOException e) {

View File

@ -5,6 +5,7 @@
*/ */
package net.sourceforge.plantuml.argon2; package net.sourceforge.plantuml.argon2;
import static java.nio.charset.StandardCharsets.UTF_8;
import static net.sourceforge.plantuml.argon2.Constants.Defaults.LANES_DEF; import static net.sourceforge.plantuml.argon2.Constants.Defaults.LANES_DEF;
import static net.sourceforge.plantuml.argon2.Constants.Defaults.LOG_M_COST_DEF; import static net.sourceforge.plantuml.argon2.Constants.Defaults.LOG_M_COST_DEF;
import static net.sourceforge.plantuml.argon2.Constants.Defaults.OUTLEN_DEF; import static net.sourceforge.plantuml.argon2.Constants.Defaults.OUTLEN_DEF;
@ -42,7 +43,6 @@ public class Argon2 {
private Argon2Type type; private Argon2Type type;
private boolean clearMemory = true; private boolean clearMemory = true;
private Charset charset = Charset.forName("UTF-8");
private boolean encodedOnly = false; private boolean encodedOnly = false;
private boolean rawOnly = false; private boolean rawOnly = false;
@ -125,11 +125,11 @@ public class Argon2 {
} }
public Argon2 setPassword(char[] password) { public Argon2 setPassword(char[] password) {
return setPassword(toByteArray(password, charset)); return setPassword(toByteArray(password, UTF_8));
} }
public Argon2 setSalt(String salt) { public Argon2 setSalt(String salt) {
return setSalt(salt.getBytes(charset)); return setSalt(salt.getBytes(UTF_8));
} }
public byte[] getOutput() { public byte[] getOutput() {
@ -254,7 +254,7 @@ public class Argon2 {
} }
public Charset getCharset() { public Charset getCharset() {
return charset; return UTF_8;
} }
public void setEncodedOnly(boolean encodedOnly) { public void setEncodedOnly(boolean encodedOnly) {

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.code; package net.sourceforge.plantuml.code;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -53,7 +55,7 @@ public class ByteArray {
} }
public String toUFT8String() throws UnsupportedEncodingException { public String toUFT8String() throws UnsupportedEncodingException {
return new String(data, 0, length, "UTF-8"); return new String(data, 0, length, UTF_8);
} }
public String toUPF9String() throws IOException { public String toUPF9String() throws IOException {

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.code; package net.sourceforge.plantuml.code;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException; import java.io.IOException;
public class TranscoderImpl implements Transcoder { public class TranscoderImpl implements Transcoder {
@ -68,7 +70,7 @@ public class TranscoderImpl implements Transcoder {
final String stringAnnoted = stringCompressor.compress(text); final String stringAnnoted = stringCompressor.compress(text);
final byte[] data; final byte[] data;
if (format == Format.UTF8) if (format == Format.UTF8)
data = stringAnnoted.getBytes("UTF-8"); data = stringAnnoted.getBytes(UTF_8);
else else
data = Upf9Encoder.getBytes(stringAnnoted); data = Upf9Encoder.getBytes(stringAnnoted);

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.creole.atom; package net.sourceforge.plantuml.creole.atom;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -184,7 +186,7 @@ public class AtomImg extends AbstractAtom implements Atom {
if (read == null) { if (read == null) {
return AtomTextUtils.createLegacy("(Cannot decode SVG: " + text + ")", fc); return AtomTextUtils.createLegacy("(Cannot decode SVG: " + text + ")", fc);
} }
return new AtomImgSvg(new TileImageSvg(new String(read, "UTF-8"))); return new AtomImgSvg(new TileImageSvg(new String(read, UTF_8)));
} }
// End // End

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.cucadiagram.dot; package net.sourceforge.plantuml.cucadiagram.dot;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -158,7 +160,7 @@ public final class CucaDiagramTxtMaker {
public List<SFile> createFiles(SFile suggestedFile) throws IOException { public List<SFile> createFiles(SFile suggestedFile) throws IOException {
if (fileFormat == FileFormat.UTXT) { if (fileFormat == FileFormat.UTXT) {
globalUg.getCharArea().print(suggestedFile.createPrintStream("UTF-8")); globalUg.getCharArea().print(suggestedFile.createPrintStream(UTF_8));
} else { } else {
globalUg.getCharArea().print(suggestedFile.createPrintStream()); globalUg.getCharArea().print(suggestedFile.createPrintStream());
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.dedication; package net.sourceforge.plantuml.dedication;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.math.BigInteger; import java.math.BigInteger;
@ -76,10 +78,10 @@ public class DedicationCrypted implements Dedication {
this.next = System.currentTimeMillis() + 5000L; this.next = System.currentTimeMillis() + 5000L;
} }
final byte[] hash1 = Noise.computeArgon2bytes(line.getBytes("UTF-8"), final byte[] hash1 = Noise.computeArgon2bytes(line.getBytes(UTF_8),
(pq.toString(35) + line).getBytes("UTF-8")); (pq.toString(35) + line).getBytes(UTF_8));
final byte[] hash2 = Noise.computeArgon2bytes(line.getBytes("UTF-8"), final byte[] hash2 = Noise.computeArgon2bytes(line.getBytes(UTF_8),
(pq.toString(36) + line).getBytes("UTF-8")); (pq.toString(36) + line).getBytes(UTF_8));
final BlumBlumShub rndBBS = new BlumBlumShub(pq, hash1); final BlumBlumShub rndBBS = new BlumBlumShub(pq, hash1);
final MTRandom rndMT = new MTRandom(hash2); final MTRandom rndMT = new MTRandom(hash2);
@ -87,7 +89,7 @@ public class DedicationCrypted implements Dedication {
byte[] current = crypted.clone(); byte[] current = crypted.clone();
Noise.shuffle(current, rndMT); Noise.shuffle(current, rndMT);
Noise.xor(current, rndBBS); Noise.xor(current, rndBBS);
Noise.xor(current, line.getBytes("UTF-8")); Noise.xor(current, line.getBytes(UTF_8));
Noise.shuffle(current, rndMT); Noise.shuffle(current, rndMT);
@ -99,7 +101,7 @@ public class DedicationCrypted implements Dedication {
Noise.shuffle(current, rndMT); Noise.shuffle(current, rndMT);
Noise.xor(current, rndBBS); Noise.xor(current, rndBBS);
final String argon = Noise.computeArgon2String(current, (pq.toString(34) + line).getBytes("UTF-8")); final String argon = Noise.computeArgon2String(current, (pq.toString(34) + line).getBytes(UTF_8));
if (this.argon2.equals(argon) == false) { if (this.argon2.equals(argon) == false) {
return null; return null;

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.dedication; package net.sourceforge.plantuml.dedication;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
public final class TinyHashableString { public final class TinyHashableString {
@ -52,7 +54,7 @@ public final class TinyHashableString {
public final synchronized int tinyHash() throws UnsupportedEncodingException { public final synchronized int tinyHash() throws UnsupportedEncodingException {
if (cachedTinyHash == -1) { if (cachedTinyHash == -1) {
cachedTinyHash = Noise.shortHash(sentence.getBytes("UTF-8"), Dedication.N.toByteArray()); cachedTinyHash = Noise.shortHash(sentence.getBytes(UTF_8), Dedication.N.toByteArray());
} }
return cachedTinyHash; return cachedTinyHash;

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.eggs; package net.sourceforge.plantuml.eggs;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
public class SentenceDecoder { public class SentenceDecoder {
@ -44,7 +46,7 @@ public class SentenceDecoder {
public SentenceDecoder(String sentence1, byte[] crypted) throws UnsupportedEncodingException { public SentenceDecoder(String sentence1, byte[] crypted) throws UnsupportedEncodingException {
final byte[] key = EggUtils.fromSecretSentence(sentence1).toByteArray(); final byte[] key = EggUtils.fromSecretSentence(sentence1).toByteArray();
final byte[] sen2 = EggUtils.xor(crypted, key); final byte[] sen2 = EggUtils.xor(crypted, key);
this.secret = new String(sen2, "UTF-8"); this.secret = new String(sen2, UTF_8);
} }
public boolean isOk() { public boolean isOk() {

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.eggs; package net.sourceforge.plantuml.eggs;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
public class SentenceProducer { public class SentenceProducer {
@ -43,7 +45,7 @@ public class SentenceProducer {
public SentenceProducer(String sentence1, String sentence2) throws UnsupportedEncodingException { public SentenceProducer(String sentence1, String sentence2) throws UnsupportedEncodingException {
final byte[] key = EggUtils.fromSecretSentence(sentence1).toByteArray(); final byte[] key = EggUtils.fromSecretSentence(sentence1).toByteArray();
final byte[] sen2 = sentence2.getBytes("UTF-8"); final byte[] sen2 = sentence2.getBytes(UTF_8);
final byte[] crypted = EggUtils.xor(sen2, key); final byte[] crypted = EggUtils.xor(sen2, key);
this.secret = EggUtils.fromByteArrays(crypted); this.secret = EggUtils.fromByteArrays(crypted);
} }

View File

@ -38,6 +38,8 @@ package net.sourceforge.plantuml.ftp;
// server // server
// FtpServer.java // FtpServer.java
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
@ -53,7 +55,6 @@ public class FtpServer {
private final Map<String, FtpConnexion> datas = new TreeMap<String, FtpConnexion>(); private final Map<String, FtpConnexion> datas = new TreeMap<String, FtpConnexion>();
private final ExecutorService exeImage = Executors.newFixedThreadPool(2); private final ExecutorService exeImage = Executors.newFixedThreadPool(2);
private final String charset = "UTF-8";
private final int listenPort; private final int listenPort;
@ -120,7 +121,7 @@ public class FtpServer {
} }
public final String getCharset() { public final String getCharset() {
return charset; return UTF_8.name();
} }
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.math; package net.sourceforge.plantuml.math;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -63,7 +65,7 @@ public class AsciiMathJs implements ScientificEquation {
static { static {
try { try {
final BufferedReader br = new BufferedReader(new InputStreamReader( final BufferedReader br = new BufferedReader(new InputStreamReader(
AsciiMathJs.class.getResourceAsStream(ASCIIMATH_PARSER_JS_LOCATION + "ASCIIMathTeXImg.js"), "UTF-8")); AsciiMathJs.class.getResourceAsStream(ASCIIMATH_PARSER_JS_LOCATION + "ASCIIMathTeXImg.js"), UTF_8));
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
String s = null; String s = null;
while ((s = br.readLine()) != null) { while ((s = br.readLine()) != null) {

View File

@ -187,7 +187,7 @@ public class PicoWebServer implements Runnable {
: "@startuml\n" + renderRequest.getSource() + "\n@enduml"; : "@startuml\n" + renderRequest.getSource() + "\n@enduml";
final SFile newCurrentDir = option.getFileDir() == null ? null : new SFile(option.getFileDir()); final SFile newCurrentDir = option.getFileDir() == null ? null : new SFile(option.getFileDir());
final SourceStringReader ssr = new SourceStringReader(option.getDefaultDefines(), source, "UTF-8", final SourceStringReader ssr = new SourceStringReader(option.getDefaultDefines(), source, UTF_8,
option.getConfig(), newCurrentDir); option.getConfig(), newCurrentDir);
final ByteArrayOutputStream os = new ByteArrayOutputStream(); final ByteArrayOutputStream os = new ByteArrayOutputStream();
final Diagram system; final Diagram system;
@ -263,7 +263,7 @@ public class PicoWebServer implements Runnable {
private void write(OutputStream os, String s) throws IOException { private void write(OutputStream os, String s) throws IOException {
s = s + "\r\n"; s = s + "\r\n";
os.write(s.getBytes("UTF-8")); os.write(s.getBytes(UTF_8));
} }
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.posimo; package net.sourceforge.plantuml.posimo;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -105,7 +107,7 @@ public class GraphvizSolverB {
throw new IllegalStateException("Timeout2 " + state); throw new IllegalStateException("Timeout2 " + state);
} }
final byte[] result = baos.toByteArray(); final byte[] result = baos.toByteArray();
final String s = new String(result, "UTF-8"); final String s = new String(result, UTF_8);
// Log.println("result=" + s); // Log.println("result=" + s);
// if (OptionFlags.getInstance().isKeepTmpFiles()) { // if (OptionFlags.getInstance().isKeepTmpFiles()) {

View File

@ -1,5 +1,7 @@
package net.sourceforge.plantuml.preproc; package net.sourceforge.plantuml.preproc;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -49,7 +51,7 @@ public class Stdlib {
if (data == null) { if (data == null) {
return null; return null;
} }
return new ByteArrayInputStream(data.getBytes("UTF-8")); return new ByteArrayInputStream(data.getBytes(UTF_8));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

View File

@ -50,6 +50,7 @@ import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -358,4 +359,8 @@ public class SFile implements Comparable<SFile> {
return new PrintStream(internal, charset); return new PrintStream(internal, charset);
} }
public PrintStream createPrintStream(Charset charset) throws FileNotFoundException, UnsupportedEncodingException {
return new PrintStream(internal, charset.name());
}
} }

View File

@ -45,6 +45,7 @@ import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -124,6 +125,11 @@ public class SecurityUtils {
return new PrintStream(os, autoFlush, charset); return new PrintStream(os, autoFlush, charset);
} }
public static PrintStream createPrintStream(OutputStream os, boolean autoFlush, Charset charset)
throws UnsupportedEncodingException {
return new PrintStream(os, autoFlush, charset.name());
}
public synchronized static BufferedImage readRasterImage(final ImageIcon imageIcon) { public synchronized static BufferedImage readRasterImage(final ImageIcon imageIcon) {
final Image tmpImage = imageIcon.getImage(); final Image tmpImage = imageIcon.getImage();
if (imageIcon.getIconWidth() == -1) { if (imageIcon.getIconWidth() == -1) {

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.sequencediagram.graphic; package net.sourceforge.plantuml.sequencediagram.graphic;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -126,7 +128,7 @@ public class SequenceDiagramTxtMaker implements FileMaker {
public ImageData createOne(OutputStream os, int index, boolean isWithMetadata) throws IOException { public ImageData createOne(OutputStream os, int index, boolean isWithMetadata) throws IOException {
if (fileFormat == FileFormat.UTXT) { if (fileFormat == FileFormat.UTXT) {
final PrintStream ps = SecurityUtils.createPrintStream(os, true, "UTF-8"); final PrintStream ps = SecurityUtils.createPrintStream(os, true, UTF_8);
ug.getCharArea().print(ps); ug.getCharArea().print(ps);
} else { } else {
final PrintStream ps = SecurityUtils.createPrintStream(os); final PrintStream ps = SecurityUtils.createPrintStream(os);

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.sprite; package net.sourceforge.plantuml.sprite;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
@ -70,9 +72,9 @@ public class RessourcesUtils {
final URL versionURL = Version.class.getClassLoader().getResource(classFile); final URL versionURL = Version.class.getClassLoader().getResource(classFile);
final String jarPath = versionURL.getPath().substring(5, versionURL.getPath().indexOf("!")); final String jarPath = versionURL.getPath().substring(5, versionURL.getPath().indexOf("!"));
if (folder) { if (folder) {
return listFolders(new JarFile(URLDecoder.decode(jarPath, "UTF-8")), path + "/"); return listFolders(new JarFile(URLDecoder.decode(jarPath, UTF_8.name())), path + "/");
} else { } else {
return listFiles(new JarFile(URLDecoder.decode(jarPath, "UTF-8")), path + "/"); return listFiles(new JarFile(URLDecoder.decode(jarPath, UTF_8.name())), path + "/");
} }
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.svek; package net.sourceforge.plantuml.svek;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -323,7 +325,7 @@ public class DotStringFactory implements Moveable {
} }
} }
final byte[] result = baos.toByteArray(); final byte[] result = baos.toByteArray();
final String s = new String(result, "UTF-8"); final String s = new String(result, UTF_8);
if (basefile != null) { if (basefile != null) {
final SFile f = basefile.getTraceFile("svek.svg"); final SFile f = basefile.getTraceFile("svek.svg");

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.tikz; package net.sourceforge.plantuml.tikz;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.PathIterator; import java.awt.geom.PathIterator;
import java.io.IOException; import java.io.IOException;
@ -271,8 +273,8 @@ public class TikzGraphics {
} }
private void out(OutputStream os, String s) throws IOException { private void out(OutputStream os, String s) throws IOException {
os.write(s.getBytes("UTF-8")); os.write(s.getBytes(UTF_8));
os.write("\n".getBytes("UTF-8")); os.write("\n".getBytes(UTF_8));
} }
public void text(double x, double y, String text, boolean underline, boolean italic, boolean bold) { public void text(double x, double y, String text, boolean underline, boolean italic, boolean bold) {

View File

@ -34,6 +34,8 @@
*/ */
package net.sourceforge.plantuml.ugraphic.debug; package net.sourceforge.plantuml.ugraphic.debug;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.Color; import java.awt.Color;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
@ -295,8 +297,8 @@ public class UGraphicDebug extends AbstractCommonUGraphic implements ClipContain
} }
private void print(OutputStream os, String out) throws UnsupportedEncodingException, IOException { private void print(OutputStream os, String out) throws UnsupportedEncodingException, IOException {
os.write(out.getBytes("UTF-8")); os.write(out.getBytes(UTF_8));
os.write("\n".getBytes("UTF-8")); os.write("\n".getBytes(UTF_8));
} }
} }

View File

@ -34,6 +34,8 @@
*/ */
package net.sourceforge.plantuml.ugraphic.txt; package net.sourceforge.plantuml.ugraphic.txt;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -115,7 +117,7 @@ public class UGraphicTxt extends AbstractCommonUGraphic implements ClipContainer
} }
public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException { public void writeImageTOBEMOVED(OutputStream os, String metadata, int dpi) throws IOException {
final PrintStream ps = SecurityUtils.createPrintStream(os, true, "UTF-8"); final PrintStream ps = SecurityUtils.createPrintStream(os, true, UTF_8);
getCharArea().print(ps); getCharArea().print(ps);
} }

View File

@ -34,6 +34,8 @@
*/ */
package net.sourceforge.plantuml.version; package net.sourceforge.plantuml.version;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -147,7 +149,7 @@ public class PLSSignature {
if (read != size) { if (read != size) {
throw new IOException(); throw new IOException();
} }
return new String(result, "UTF-8"); return new String(result, UTF_8);
} }
private static long readLong(ByteArrayInputStream bais) throws IOException { private static long readLong(ByteArrayInputStream bais) throws IOException {
@ -207,7 +209,7 @@ public class PLSSignature {
} }
public static byte[] getSalt(final String signature) throws UnsupportedEncodingException { public static byte[] getSalt(final String signature) throws UnsupportedEncodingException {
final Random rnd = new Random(getSeed(signature.getBytes("UTF-8"))); final Random rnd = new Random(getSeed(signature.getBytes(UTF_8)));
final byte salt[] = new byte[512]; final byte salt[] = new byte[512];
rnd.nextBytes(salt); rnd.nextBytes(salt);
return salt; return salt;

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.xmi; package net.sourceforge.plantuml.xmi;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -133,7 +135,7 @@ abstract class XmiClassDiagramAbstract implements IXmiClassDiagram {
final Transformer transformer = fabrique.newTransformer(); final Transformer transformer = fabrique.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name());
// tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); // tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(source, resultat); transformer.transform(source, resultat);
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.xmi; package net.sourceforge.plantuml.xmi;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -234,7 +236,7 @@ public class XmiDescriptionDiagram implements IXmiClassDiagram {
final Transformer transformer = fabrique.newTransformer(); final Transformer transformer = fabrique.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name());
// tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); // tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(source, resultat); transformer.transform(source, resultat);
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.xmi; package net.sourceforge.plantuml.xmi;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -248,7 +250,7 @@ public class XmiStateDiagram implements IXmiClassDiagram {
final Transformer transformer = fabrique.newTransformer(); final Transformer transformer = fabrique.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name());
// tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); // tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(source, resultat); transformer.transform(source, resultat);
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.xmlsc; package net.sourceforge.plantuml.xmlsc;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.OutputStream; import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -133,7 +135,7 @@ public class ScxmlStateDiagramStandard {
final TransformerFactory fabrique = TransformerFactory.newInstance(); final TransformerFactory fabrique = TransformerFactory.newInstance();
final Transformer transformer = fabrique.newTransformer(); final Transformer transformer = fabrique.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.ENCODING, UTF_8.name());
transformer.transform(source, resultat); transformer.transform(source, resultat);
} }

View File

@ -1,5 +1,6 @@
package net.sourceforge.plantuml.code; package net.sourceforge.plantuml.code;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
@ -13,8 +14,8 @@ class CompressionTest {
@Test @Test
public void no_100_000_limit() throws Exception { public void no_100_000_limit() throws Exception {
final Compression compression = new CompressionZlib(); final Compression compression = new CompressionZlib();
compression.decompress(compression.compress(repeat("x", 100_000).getBytes("UTF-8"))); compression.decompress(compression.compress(repeat("x", 100_000).getBytes(UTF_8)));
compression.decompress(compression.compress(repeat("x", 100_001).getBytes("UTF-8"))); compression.decompress(compression.compress(repeat("x", 100_001).getBytes(UTF_8)));
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder(); final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
transcoder.decode(transcoder.encode(repeat("x", 100_000))); transcoder.decode(transcoder.encode(repeat("x", 100_000)));

View File

@ -19,7 +19,7 @@ public class TestUtils {
final Option option = new Option(options); final Option option = new Option(options);
option.setFileFormatOption(new FileFormatOption(FileFormat.UTXT)); option.setFileFormatOption(new FileFormatOption(FileFormat.UTXT));
final SourceStringReader ssr = new SourceStringReader(option.getDefaultDefines(), source, "UTF-8", option.getConfig()); final SourceStringReader ssr = new SourceStringReader(option.getDefaultDefines(), source, UTF_8.name(), option.getConfig());
final ByteArrayOutputStream os = new ByteArrayOutputStream(); final ByteArrayOutputStream os = new ByteArrayOutputStream();

View File

@ -1,5 +1,6 @@
package nonreg; package nonreg;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -7,8 +8,6 @@ import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -33,8 +32,6 @@ public class BasicTest {
private static final String TRIPLE_QUOTE = "\"\"\""; private static final String TRIPLE_QUOTE = "\"\"\"";
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final boolean FORCE_RESULT_GENERATION = false; private static final boolean FORCE_RESULT_GENERATION = false;
private static final boolean ENABLE_RESULT_GENERATION_IF_NONE_PRESENT = false; private static final boolean ENABLE_RESULT_GENERATION_IF_NONE_PRESENT = false;
@ -49,7 +46,7 @@ public class BasicTest {
final String actualResult = runPlantUML(expectedDescription); final String actualResult = runPlantUML(expectedDescription);
if (FORCE_RESULT_GENERATION if (FORCE_RESULT_GENERATION
|| (ENABLE_RESULT_GENERATION_IF_NONE_PRESENT && Files.exists(getResultFile()) == false)) { || (ENABLE_RESULT_GENERATION_IF_NONE_PRESENT && Files.exists(getResultFile()) == false)) {
generatedResultJavaFile(actualResult, actualResult.getBytes(UTF8)); generatedResultJavaFile(actualResult, actualResult.getBytes(UTF_8));
} }
final String imageExpectedResult = readTripleQuotedString(getResultFile()); final String imageExpectedResult = readTripleQuotedString(getResultFile());
assertEquals(imageExpectedResult, actualResult); assertEquals(imageExpectedResult, actualResult);
@ -57,7 +54,7 @@ public class BasicTest {
private void generatedResultJavaFile(String actualResult, byte[] bytes) throws IOException { private void generatedResultJavaFile(String actualResult, byte[] bytes) throws IOException {
try (BufferedWriter writer = Files.newBufferedWriter(getResultFile(), StandardCharsets.UTF_8)) { try (BufferedWriter writer = Files.newBufferedWriter(getResultFile(), UTF_8)) {
writer.write("package " + getPackageName() + ";\n"); writer.write("package " + getPackageName() + ";\n");
writer.write("\n"); writer.write("\n");
writer.write("public class " + getClass().getSimpleName() + "Result {\n"); writer.write("public class " + getClass().getSimpleName() + "Result {\n");
@ -89,18 +86,18 @@ public class BasicTest {
protected String runPlantUML(String expectedDescription) throws IOException, UnsupportedEncodingException { protected String runPlantUML(String expectedDescription) throws IOException, UnsupportedEncodingException {
final String diagramText = readTripleQuotedString(getDiagramFile()); final String diagramText = readTripleQuotedString(getDiagramFile());
final SourceStringReader ssr = new SourceStringReader(diagramText, "UTF-8"); final SourceStringReader ssr = new SourceStringReader(diagramText, UTF_8);
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DiagramDescription diagramDescription = ssr.outputImage(baos, 0, new FileFormatOption(FileFormat.DEBUG)); final DiagramDescription diagramDescription = ssr.outputImage(baos, 0, new FileFormatOption(FileFormat.DEBUG));
assertEquals(expectedDescription, diagramDescription.getDescription(), "Bad description"); assertEquals(expectedDescription, diagramDescription.getDescription(), "Bad description");
return new String(baos.toByteArray(), UTF8); return new String(baos.toByteArray(), UTF_8);
} }
protected String readTripleQuotedString(Path path) throws IOException { protected String readTripleQuotedString(Path path) throws IOException {
assertTrue(Files.exists(path), "Cannot find " + path); assertTrue(Files.exists(path), "Cannot find " + path);
assertTrue(Files.isReadable(path), "Cannot read " + path); assertTrue(Files.isReadable(path), "Cannot read " + path);
final List<String> allLines = Files.readAllLines(path, UTF8); final List<String> allLines = Files.readAllLines(path, UTF_8);
final int first = allLines.indexOf(TRIPLE_QUOTE); final int first = allLines.indexOf(TRIPLE_QUOTE);
final int last = allLines.lastIndexOf(TRIPLE_QUOTE); final int last = allLines.lastIndexOf(TRIPLE_QUOTE);
assertTrue(first != -1); assertTrue(first != -1);