updated Gradle and lys-catalog versions
CI / build (push) Successful in 24s

This commit is contained in:
2025-04-19 22:05:38 +08:00
parent ef2ee4a86c
commit 3b55366347
10 changed files with 76 additions and 14 deletions
+29
View File
@@ -90,7 +90,36 @@ public class Hash {
return new String(hexChars);
}
private static int charToInt(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
} else if(c >= 'a' && c <= 'f') {
return 10 + c - 'a';
} else if(c >= 'A' && c <= 'F') {
return 10 + c - 'A';
} else {
throw newThrowable(IllegalArgumentException.class, "Illegal hex character '%c'", c);
}
}
public static byte[] hexToBytes(String hexString) {
if (hexString.length() % 2 != 0) {
throw newThrowable(IllegalArgumentException.class, "Hex string length must be even," +
" string has length '%d' instead", hexString.length());
}
byte[] result = new byte[hexString.length() / 2];
for(int i = 0; i < hexString.length(); i++) {
int value = charToInt(hexString.charAt(i));
if (i % 2 == 0) {
result[i / 2] += (byte) (value << 4);
} else {
result[i / 2] += (byte) value;
}
}
return result;
}
public static byte[] hexToBytes2(String hexString) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (hexString.length() % 2 != 0) {
throw newThrowable(IllegalArgumentException.class, "Hex string length must be even," +
+4
View File
@@ -237,6 +237,10 @@ public class JWO {
return Hash.bytesToHex(bytes);
}
public static byte[] hexToBytes(String hexStr) {
return Hash.hexToBytes(hexStr);
}
@SneakyThrows
public static void deletePath(Path path) {
Files.walk(path)
@@ -65,6 +65,7 @@ public class HashTest {
);
}
}
@ArgumentsSource(HexTestArguments.class)
@ParameterizedTest
public void hexTest(String sourceString, Class<? extends Throwable> t) {
@@ -78,4 +79,18 @@ public class HashTest {
Assertions.assertEquals(sourceString.toUpperCase(), Hash.bytesToHex(bytes));
}
}
@ArgumentsSource(HexTestArguments.class)
@ParameterizedTest
public void hexTest2(String sourceString, Class<? extends Throwable> t) {
if(t != null) {
Assertions.assertThrows(t, () ->
Hash.hexToBytes2(sourceString)
);
} else {
byte[] bytes = Hash.hexToBytes2(sourceString);
Assertions.assertEquals(sourceString.length() / 2, bytes.length);
Assertions.assertEquals(sourceString.toUpperCase(), Hash.bytesToHex(bytes));
}
}
}
@@ -82,7 +82,7 @@ public class JavaVersionTest {
JWO.copy(is, baos);
}
final var jwoClassVersion = JavaVersion.forClass(baos.toByteArray());
assertEquals(JavaVersion.VERSION_1_8, jwoClassVersion);
assertEquals(JavaVersion.VERSION_11, jwoClassVersion);
}
}
}