mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-15 18:37:17 +01:00
74 lines
3.6 KiB
Java
74 lines
3.6 KiB
Java
package org.java_websocket.util;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.charset.CharacterCodingException;
|
|
import java.nio.charset.CharsetDecoder;
|
|
import java.nio.charset.CodingErrorAction;
|
|
import java.nio.charset.StandardCharsets;
|
|
import org.java_websocket.exceptions.InvalidDataException;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes11.dex */
|
|
public class Charsetfunctions {
|
|
private static final CodingErrorAction codingErrorAction = CodingErrorAction.REPORT;
|
|
private static final int[] utf8d = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 1, 2, 3, 5, 8, 7, 1, 1, 1, 4, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
|
|
|
private Charsetfunctions() {
|
|
}
|
|
|
|
public static byte[] asciiBytes(String str) {
|
|
return str.getBytes(StandardCharsets.US_ASCII);
|
|
}
|
|
|
|
public static boolean isValidUTF8(ByteBuffer byteBuffer, int i) {
|
|
int remaining = byteBuffer.remaining();
|
|
if (remaining < i) {
|
|
return false;
|
|
}
|
|
int i2 = 0;
|
|
while (i < remaining) {
|
|
int[] iArr = utf8d;
|
|
i2 = iArr[(i2 << 4) + 256 + iArr[byteBuffer.get(i) & 255]];
|
|
if (i2 == 1) {
|
|
return false;
|
|
}
|
|
i++;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static String stringAscii(byte[] bArr, int i, int i2) {
|
|
return new String(bArr, i, i2, StandardCharsets.US_ASCII);
|
|
}
|
|
|
|
public static String stringUtf8(ByteBuffer byteBuffer) throws InvalidDataException {
|
|
CharsetDecoder newDecoder = StandardCharsets.UTF_8.newDecoder();
|
|
CodingErrorAction codingErrorAction2 = codingErrorAction;
|
|
newDecoder.onMalformedInput(codingErrorAction2);
|
|
newDecoder.onUnmappableCharacter(codingErrorAction2);
|
|
try {
|
|
byteBuffer.mark();
|
|
String charBuffer = newDecoder.decode(byteBuffer).toString();
|
|
byteBuffer.reset();
|
|
return charBuffer;
|
|
} catch (CharacterCodingException e) {
|
|
throw new InvalidDataException(1007, e);
|
|
}
|
|
}
|
|
|
|
public static byte[] utf8Bytes(String str) {
|
|
return str.getBytes(StandardCharsets.UTF_8);
|
|
}
|
|
|
|
public static String stringAscii(byte[] bArr) {
|
|
return stringAscii(bArr, 0, bArr.length);
|
|
}
|
|
|
|
public static boolean isValidUTF8(ByteBuffer byteBuffer) {
|
|
return isValidUTF8(byteBuffer, 0);
|
|
}
|
|
|
|
public static String stringUtf8(byte[] bArr) throws InvalidDataException {
|
|
return stringUtf8(ByteBuffer.wrap(bArr));
|
|
}
|
|
}
|