package edu.practice.zapper;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
public class Zapper {
private static final String UNICODE_START = "&#";
private static final String UNICODE_END = ";";
private String input;
public Zapper() {
}
public String unicodePrint(String input) {
if (input != null && !input.isEmpty()) {
StringBuilder sbTitle = new StringBuilder();
System.err.println(input);
input.codePoints().forEach(codepoint->{
if (codepoint > 127) {
sbTitle.append(UNICODE_START);
sbTitle.append(codepoint);
sbTitle.append(UNICODE_END);
} else {
sbTitle.appendCodePoint(codepoint);
}
});
input = sbTitle.toString();
System.err.println(input);
}
return input;
}
public static void main(String[] args) {
Zapper z = new Zapper();
z.input = "挑战";
if(args.length > 0) {
System.out.println("Restarting:%s :%d :%d".formatted(z.input,z.input.codePointAt(0),z.input.codePointAt(1)));
}
String encodeString = Base64.getEncoder().encodeToString(z.input.getBytes());
byte[] decodeBytes = Base64.getDecoder().decode(encodeString);
String decodeStringU = new String(decodeBytes,Charset.forName("UTF-8"));
String decodeString = new String(decodeBytes);
z.unicodePrint(decodeStringU);
z.unicodePrint(decodeString);
if(args.length < 1) {
restartApplication();
}
}
private static Process restartApplication() {
Process process = null;
while (process == null) {
List command = new ArrayList();
command.add("java");
command.add("-Ddebugging=false");
command.add("-DdebugUnit=None");
command.add("-jar");
command.add("zapper-1-jar-with-dependencies.jar");
command.add("restarted");
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectOutput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
try {
process = pb.start();
Thread.sleep(5_000);
} catch (IOException | InterruptedException e) {
System.out.println(e.getMessage());
}
}
return process;
}
}
Я привел пример, чтобы облегчить расследование. Примерно так я и делаю, но можно пойти и тем, что есть. В любом случае, очевидно, каков ответ на исходный вопрос. Но СЕЙЧАС перезапуск просто приводит к испорченности всех ??, и я не понимаю, почему. Похоже, одно из декодирований должно сработать.
Результаты:
挑战
挑战
挑战
挑战
Restarting:?? :25361 :25112
??
??
??
??