This commit is contained in:
crschnick
2025-07-04 07:52:51 +00:00
parent c598970fd8
commit ff869b52d4
14 changed files with 26 additions and 114 deletions

View File

@@ -5,7 +5,7 @@ import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.beacon.BeaconClientException;
import io.xpipe.beacon.api.ConnectionAddExchange;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import com.sun.net.httpserver.HttpExchange;

View File

@@ -1,4 +1,4 @@
package io.xpipe.core.util;
package io.xpipe.app.ext;
import lombok.experimental.StandardException;

View File

@@ -11,7 +11,7 @@ import io.xpipe.app.util.*;
import io.xpipe.core.process.ShellTtyState;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.ValidatableStore;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;

View File

@@ -7,7 +7,7 @@ import io.xpipe.app.issue.ErrorEventFactory;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.prefs.SupportedLocale;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import java.nio.file.Files;
import java.nio.file.Path;

View File

@@ -8,7 +8,7 @@ import io.xpipe.app.util.Validators;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.store.FilePath;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

View File

@@ -4,7 +4,7 @@ import io.xpipe.app.ext.ProcessControlProvider;
import io.xpipe.app.issue.ErrorEventFactory;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.core.util.InPlaceSecretValue;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

View File

@@ -3,7 +3,7 @@ package io.xpipe.app.util;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import java.util.List;

View File

@@ -44,9 +44,6 @@ public class CoreJacksonModule extends SimpleModule {
addSerializer(ShellDialect.class, new ShellDialectSerializer());
addDeserializer(ShellDialect.class, new ShellDialectDeserializer());
addSerializer(StreamCharset.class, new StreamCharsetSerializer());
addDeserializer(StreamCharset.class, new StreamCharsetDeserializer());
addSerializer(NewLine.class, new NewLineSerializer());
addDeserializer(NewLine.class, new NewLineDeserializer());
@@ -175,22 +172,6 @@ public class CoreJacksonModule extends SimpleModule {
}
}
public static class StreamCharsetSerializer extends JsonSerializer<StreamCharset> {
@Override
public void serialize(StreamCharset value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.toString());
}
}
public static class StreamCharsetDeserializer extends JsonDeserializer<StreamCharset> {
@Override
public StreamCharset deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return StreamCharset.get(p.getValueAsString());
}
}
public static class LocalPathSerializer extends JsonSerializer<Path> {
@Override

View File

@@ -1,22 +0,0 @@
package io.xpipe.core.util;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class Identifiers {
@SafeVarargs
public static List<String> join(List<String>... s) {
return Arrays.stream(s).flatMap(Collection::stream).toList();
}
public static List<String> get(String... s) {
return nameAlternatives(Arrays.asList(s));
}
private static List<String> nameAlternatives(List<String> split) {
return List.of(
String.join("", split), String.join(" ", split), String.join("_", split), String.join("-", split));
}
}

View File

@@ -17,32 +17,29 @@ import java.util.stream.Stream;
public class StreamCharset {
public static final StreamCharset UTF8 =
new StreamCharset(StandardCharsets.UTF_8, null, Identifiers.get("utf", "8"));
new StreamCharset(StandardCharsets.UTF_8, null);
public static final StreamCharset UTF8_BOM = new StreamCharset(
StandardCharsets.UTF_8,
new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF},
Identifiers.get("utf", "8", "bom"));
new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
// ======
// UTF-16
// ======
public static final StreamCharset UTF16_BE =
new StreamCharset(StandardCharsets.UTF_16BE, null, Identifiers.get("utf", "16", "be"));
new StreamCharset(StandardCharsets.UTF_16BE, null);
public static final StreamCharset UTF16_BE_BOM = new StreamCharset(
StandardCharsets.UTF_16BE,
new byte[] {(byte) 0xFE, (byte) 0xFF},
Identifiers.get("utf", "16", "be", "bom"));
new byte[] {(byte) 0xFE, (byte) 0xFF});
public static final StreamCharset UTF16_LE =
new StreamCharset(StandardCharsets.UTF_16LE, null, Identifiers.get("utf", "16", "le"));
new StreamCharset(StandardCharsets.UTF_16LE, null);
public static final StreamCharset UTF16_LE_BOM = new StreamCharset(
StandardCharsets.UTF_16LE,
new byte[] {(byte) 0xFF, (byte) 0xFE},
Identifiers.get("utf", "16", "le", "bom"));
new byte[] {(byte) 0xFF, (byte) 0xFE});
public static final StreamCharset UTF16 = UTF16_LE;
@@ -55,69 +52,40 @@ public class StreamCharset {
UTF16_BOM,
new StreamCharset(
StandardCharsets.US_ASCII,
null,
Identifiers.join(Identifiers.get("ascii"), Identifiers.get("us", "ascii"))),
null),
new StreamCharset(
StandardCharsets.ISO_8859_1,
null,
Identifiers.join(
Identifiers.get("iso", "8859"),
Identifiers.get("iso", "8859", "1"),
Identifiers.get("8859"),
Identifiers.get("8859", "1"))),
null),
new StreamCharset(
Charset.forName("Windows-1251"),
null,
Identifiers.join(Identifiers.get("windows", "1251"), Identifiers.get("1251"))),
null),
new StreamCharset(
Charset.forName("Windows-1252"),
null,
Identifiers.join(Identifiers.get("windows", "1252"), Identifiers.get("1252"))));
null));
// ======
// UTF-32
// ======
public static final StreamCharset UTF32_LE =
new StreamCharset(Charset.forName("utf-32le"), null, Identifiers.get("utf", "32", "le"));
new StreamCharset(Charset.forName("utf-32le"), null);
public static final StreamCharset UTF32_LE_BOM = new StreamCharset(
Charset.forName("utf-32le"),
new byte[] {0x00, 0x00, (byte) 0xFE, (byte) 0xFF},
Identifiers.get("utf", "32", "le", "bom"));
new byte[] {0x00, 0x00, (byte) 0xFE, (byte) 0xFF});
public static final StreamCharset UTF32_BE =
new StreamCharset(Charset.forName("utf-32be"), null, Identifiers.get("utf", "32", "be"));
new StreamCharset(Charset.forName("utf-32be"), null);
public static final StreamCharset UTF32_BE_BOM = new StreamCharset(
Charset.forName("utf-32be"),
new byte[] {
(byte) 0xFF, (byte) 0xFE, 0x00, 0x00,
},
Identifiers.get("utf", "32", "be", "bom"));
private static final List<StreamCharset> RARE_NAMED =
});
private static final List<StreamCharset> RARE =
List.of(UTF16_LE, UTF16_LE_BOM, UTF16_BE, UTF16_BE_BOM, UTF32_LE, UTF32_LE_BOM, UTF32_BE, UTF32_BE_BOM);
public static final List<StreamCharset> RARE = Stream.concat(
RARE_NAMED.stream(),
Charset.availableCharsets().values().stream()
.filter(charset -> !charset.equals(StandardCharsets.UTF_16)
&& !charset.equals(Charset.forName("utf-32"))
&& !charset.displayName().startsWith("x-")
&& !charset.displayName().startsWith("X-")
&& !charset.displayName().endsWith("-BOM")
&& COMMON.stream()
.noneMatch(c -> c.getCharset().equals(charset))
&& RARE_NAMED.stream()
.noneMatch(c -> c.getCharset().equals(charset)))
.map(charset -> new StreamCharset(
charset,
null,
Identifiers.get(charset.name().split("-")))))
.toList();
public static final List<StreamCharset> ALL =
Stream.concat(COMMON.stream(), RARE.stream()).toList();
Charset charset;
byte[] byteOrderMark;
List<String> names;
public static StreamCharset get(Charset charset, boolean byteOrderMark) {
return ALL.stream()
@@ -127,17 +95,6 @@ public class StreamCharset {
.orElseThrow();
}
public static StreamCharset get(String s) {
var found = ALL.stream()
.filter(streamCharset -> streamCharset.getNames().contains(s.toLowerCase(Locale.ROOT)))
.findFirst();
if (found.isEmpty()) {
throw new IllegalArgumentException("Unknown charset name: " + s);
}
return found.get();
}
public static InputStreamReader detectedReader(InputStream inputStream) throws Exception {
StreamCharset detected = null;
for (var charset : StreamCharset.COMMON) {
@@ -215,10 +172,6 @@ public class StreamCharset {
return charset.equals(that.charset) && Arrays.equals(byteOrderMark, that.byteOrderMark);
}
public String toString() {
return getNames().getFirst();
}
public boolean hasByteOrderMark() {
return byteOrderMark != null;
}

View File

@@ -7,7 +7,7 @@ import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.EncryptedValue;
import io.xpipe.app.util.SecretRetrievalStrategy;
import io.xpipe.app.util.Validators;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

View File

@@ -9,7 +9,7 @@ import io.xpipe.core.process.*;
import io.xpipe.core.store.FilePath;
import io.xpipe.core.util.KeyValue;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

View File

@@ -3,7 +3,7 @@ package io.xpipe.ext.base.identity;
import io.xpipe.app.ext.UserScopeStore;
import io.xpipe.app.util.EncryptedValue;
import io.xpipe.app.util.SecretRetrievalStrategy;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import com.fasterxml.jackson.annotation.JsonTypeName;
import lombok.EqualsAndHashCode;

View File

@@ -6,7 +6,7 @@ import io.xpipe.app.util.ScriptHelper;
import io.xpipe.app.util.Validators;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.process.ShellDialect;
import io.xpipe.core.util.ValidationException;
import io.xpipe.app.ext.ValidationException;
import io.xpipe.app.ext.SelfReferentialStore;
import com.fasterxml.jackson.annotation.JsonTypeName;