mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 01:47:17 +01:00
84 lines
3.2 KiB
Java
84 lines
3.2 KiB
Java
package androidx.emoji2.text.flatbuffer;
|
|
|
|
import com.google.common.math.Stats$$ExternalSyntheticLambda0;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.CharBuffer;
|
|
import java.nio.charset.CharacterCodingException;
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.CharsetDecoder;
|
|
import java.nio.charset.CharsetEncoder;
|
|
import java.nio.charset.CoderResult;
|
|
import java.nio.charset.StandardCharsets;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes14.dex */
|
|
public class Utf8Old extends Utf8 {
|
|
private static final ThreadLocal<Cache> CACHE = ThreadLocal.withInitial(new Stats$$ExternalSyntheticLambda0(1));
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class Cache {
|
|
final CharsetDecoder decoder;
|
|
final CharsetEncoder encoder;
|
|
CharSequence lastInput = null;
|
|
ByteBuffer lastOutput = null;
|
|
|
|
public Cache() {
|
|
Charset charset = StandardCharsets.UTF_8;
|
|
this.encoder = charset.newEncoder();
|
|
this.decoder = charset.newDecoder();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static /* synthetic */ Cache lambda$static$0() {
|
|
return new Cache();
|
|
}
|
|
|
|
@Override // androidx.emoji2.text.flatbuffer.Utf8
|
|
public String decodeUtf8(ByteBuffer byteBuffer, int i, int i2) {
|
|
CharsetDecoder charsetDecoder = CACHE.get().decoder;
|
|
charsetDecoder.reset();
|
|
ByteBuffer duplicate = byteBuffer.duplicate();
|
|
duplicate.position(i);
|
|
duplicate.limit(i + i2);
|
|
try {
|
|
return charsetDecoder.decode(duplicate).toString();
|
|
} catch (CharacterCodingException e) {
|
|
Single$$ExternalSyntheticBUOutline0.m("Bad encoding", e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override // androidx.emoji2.text.flatbuffer.Utf8
|
|
public void encodeUtf8(CharSequence charSequence, ByteBuffer byteBuffer) {
|
|
Cache cache = CACHE.get();
|
|
if (cache.lastInput != charSequence) {
|
|
encodedLength(charSequence);
|
|
}
|
|
byteBuffer.put(cache.lastOutput);
|
|
}
|
|
|
|
@Override // androidx.emoji2.text.flatbuffer.Utf8
|
|
public int encodedLength(CharSequence charSequence) {
|
|
Cache cache = CACHE.get();
|
|
int maxBytesPerChar = (int) (cache.encoder.maxBytesPerChar() * charSequence.length());
|
|
ByteBuffer byteBuffer = cache.lastOutput;
|
|
if (byteBuffer == null || byteBuffer.capacity() < maxBytesPerChar) {
|
|
cache.lastOutput = ByteBuffer.allocate(Math.max(128, maxBytesPerChar));
|
|
}
|
|
cache.lastOutput.clear();
|
|
cache.lastInput = charSequence;
|
|
CoderResult encode = cache.encoder.encode(charSequence instanceof CharBuffer ? (CharBuffer) charSequence : CharBuffer.wrap(charSequence), cache.lastOutput, true);
|
|
if (encode.isError()) {
|
|
try {
|
|
encode.throwException();
|
|
} catch (CharacterCodingException e) {
|
|
Single$$ExternalSyntheticBUOutline0.m("bad character encoding", e);
|
|
return 0;
|
|
}
|
|
}
|
|
cache.lastOutput.flip();
|
|
return cache.lastOutput.remaining();
|
|
}
|
|
}
|