package com.fasterxml.jackson.core.json;

import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.PrettyPrinter;
import com.fasterxml.jackson.core.SerializableString;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.CharacterEscapes;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.google.android.gms.common.api.Api;
import com.google.firebase.perf.util.Constants;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.math.BigDecimal;
import java.math.BigInteger;

/* loaded from: classes.dex */
public class WriterBasedJsonGenerator extends JsonGeneratorImpl {
    protected static final char[] HEX_CHARS = CharTypes.copyHexChars();
    protected static final int SHORT_WRITE = 32;
    protected char[] _copyBuffer;
    protected SerializableString _currentEscape;
    protected char[] _entityBuffer;
    protected char[] _outputBuffer;
    protected int _outputEnd;
    protected int _outputHead;
    protected int _outputTail;
    protected char _quoteChar;
    protected final Writer _writer;

    @Deprecated
    public WriterBasedJsonGenerator(IOContext iOContext, int i10, ObjectCodec objectCodec, Writer writer) {
        this(iOContext, i10, objectCodec, writer, JsonFactory.DEFAULT_QUOTE_CHAR);
    }

    private char[] _allocateCopyBuffer() {
        if (this._copyBuffer == null) {
            this._copyBuffer = this._ioContext.allocNameCopyBuffer(2000);
        }
        return this._copyBuffer;
    }

    private char[] _allocateEntityBuffer() {
        char[] cArr = {'\\', 0, '\\', 'u', '0', '0', 0, 0, '\\', 'u'};
        this._entityBuffer = cArr;
        return cArr;
    }

    private void _appendCharacterEscape(char c10, int i10) throws IOException, JsonGenerationException {
        String value;
        int i11;
        if (i10 >= 0) {
            if (this._outputTail + 2 > this._outputEnd) {
                _flushBuffer();
            }
            char[] cArr = this._outputBuffer;
            int i12 = this._outputTail;
            int i13 = i12 + 1;
            cArr[i12] = '\\';
            this._outputTail = i13 + 1;
            cArr[i13] = (char) i10;
            return;
        }
        if (i10 == -2) {
            SerializableString serializableString = this._currentEscape;
            if (serializableString == null) {
                value = this._characterEscapes.getEscapeSequence(c10).getValue();
            } else {
                value = serializableString.getValue();
                this._currentEscape = null;
            }
            int length = value.length();
            if (this._outputTail + length > this._outputEnd) {
                _flushBuffer();
                if (length > this._outputEnd) {
                    this._writer.write(value);
                    return;
                }
            }
            value.getChars(0, length, this._outputBuffer, this._outputTail);
            this._outputTail += length;
            return;
        }
        if (this._outputTail + 5 >= this._outputEnd) {
            _flushBuffer();
        }
        int i14 = this._outputTail;
        char[] cArr2 = this._outputBuffer;
        int i15 = i14 + 1;
        cArr2[i14] = '\\';
        int i16 = i15 + 1;
        cArr2[i15] = 'u';
        if (c10 > 255) {
            int i17 = 255 & (c10 >> '\b');
            int i18 = i16 + 1;
            char[] cArr3 = HEX_CHARS;
            cArr2[i16] = cArr3[i17 >> 4];
            i11 = i18 + 1;
            cArr2[i18] = cArr3[i17 & 15];
            c10 = (char) (c10 & 255);
        } else {
            int i19 = i16 + 1;
            cArr2[i16] = '0';
            i11 = i19 + 1;
            cArr2[i19] = '0';
        }
        int i20 = i11 + 1;
        char[] cArr4 = HEX_CHARS;
        cArr2[i11] = cArr4[c10 >> 4];
        cArr2[i20] = cArr4[c10 & 15];
        this._outputTail = i20 + 1;
    }

    private void _prependOrWriteCharacterEscape(char c10, int i10) throws IOException, JsonGenerationException {
        String value;
        int i11;
        if (i10 >= 0) {
            int i12 = this._outputTail;
            if (i12 >= 2) {
                int i13 = i12 - 2;
                this._outputHead = i13;
                char[] cArr = this._outputBuffer;
                cArr[i13] = '\\';
                cArr[i13 + 1] = (char) i10;
                return;
            }
            char[] cArr2 = this._entityBuffer;
            if (cArr2 == null) {
                cArr2 = _allocateEntityBuffer();
            }
            this._outputHead = this._outputTail;
            cArr2[1] = (char) i10;
            this._writer.write(cArr2, 0, 2);
            return;
        }
        if (i10 != -2) {
            int i14 = this._outputTail;
            if (i14 >= 6) {
                char[] cArr3 = this._outputBuffer;
                int i15 = i14 - 6;
                this._outputHead = i15;
                cArr3[i15] = '\\';
                int i16 = i15 + 1;
                cArr3[i16] = 'u';
                if (c10 > 255) {
                    int i17 = (c10 >> '\b') & Constants.MAX_HOST_LENGTH;
                    int i18 = i16 + 1;
                    char[] cArr4 = HEX_CHARS;
                    cArr3[i18] = cArr4[i17 >> 4];
                    i11 = i18 + 1;
                    cArr3[i11] = cArr4[i17 & 15];
                    c10 = (char) (c10 & 255);
                } else {
                    int i19 = i16 + 1;
                    cArr3[i19] = '0';
                    i11 = i19 + 1;
                    cArr3[i11] = '0';
                }
                int i20 = i11 + 1;
                char[] cArr5 = HEX_CHARS;
                cArr3[i20] = cArr5[c10 >> 4];
                cArr3[i20 + 1] = cArr5[c10 & 15];
                return;
            }
            char[] cArr6 = this._entityBuffer;
            if (cArr6 == null) {
                cArr6 = _allocateEntityBuffer();
            }
            this._outputHead = this._outputTail;
            if (c10 > 255) {
                int i21 = (c10 >> '\b') & Constants.MAX_HOST_LENGTH;
                int i22 = c10 & 255;
                char[] cArr7 = HEX_CHARS;
                cArr6[10] = cArr7[i21 >> 4];
                cArr6[11] = cArr7[i21 & 15];
                cArr6[12] = cArr7[i22 >> 4];
                cArr6[13] = cArr7[i22 & 15];
                this._writer.write(cArr6, 8, 6);
                return;
            }
            char[] cArr8 = HEX_CHARS;
            cArr6[6] = cArr8[c10 >> 4];
            cArr6[7] = cArr8[c10 & 15];
            this._writer.write(cArr6, 2, 6);
            return;
        }
        SerializableString serializableString = this._currentEscape;
        if (serializableString == null) {
            value = this._characterEscapes.getEscapeSequence(c10).getValue();
        } else {
            value = serializableString.getValue();
            this._currentEscape = null;
        }
        int length = value.length();
        int i23 = this._outputTail;
        if (i23 >= length) {
            int i24 = i23 - length;
            this._outputHead = i24;
            value.getChars(0, length, this._outputBuffer, i24);
        } else {
            this._outputHead = i23;
            this._writer.write(value);
        }
    }

    private int _readMore(InputStream inputStream, byte[] bArr, int i10, int i11, int i12) throws IOException {
        int i13 = 0;
        while (i10 < i11) {
            bArr[i13] = bArr[i10];
            i13++;
            i10++;
        }
        int min = Math.min(i12, bArr.length);
        do {
            int i14 = min - i13;
            if (i14 == 0) {
                break;
            }
            int read = inputStream.read(bArr, i13, i14);
            if (read < 0) {
                return i13;
            }
            i13 += read;
        } while (i13 < 3);
        return i13;
    }

    private final void _writeFieldNameTail(SerializableString serializableString) throws IOException {
        char[] asQuotedChars = serializableString.asQuotedChars();
        writeRaw(asQuotedChars, 0, asQuotedChars.length);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = this._quoteChar;
    }

    private void _writeLongString(String str) throws IOException {
        _flushBuffer();
        int length = str.length();
        int i10 = 0;
        while (true) {
            int i11 = this._outputEnd;
            if (i10 + i11 > length) {
                i11 = length - i10;
            }
            int i12 = i10 + i11;
            str.getChars(i10, i12, this._outputBuffer, 0);
            if (this._characterEscapes != null) {
                _writeSegmentCustom(i11);
            } else {
                int i13 = this._maximumNonEscapedChar;
                if (i13 != 0) {
                    _writeSegmentASCII(i11, i13);
                } else {
                    _writeSegment(i11);
                }
            }
            if (i12 >= length) {
                return;
            } else {
                i10 = i12;
            }
        }
    }

    private final void _writeNull() throws IOException {
        if (this._outputTail + 4 >= this._outputEnd) {
            _flushBuffer();
        }
        int i10 = this._outputTail;
        char[] cArr = this._outputBuffer;
        cArr[i10] = 'n';
        int i11 = i10 + 1;
        cArr[i11] = 'u';
        int i12 = i11 + 1;
        cArr[i12] = 'l';
        int i13 = i12 + 1;
        cArr[i13] = 'l';
        this._outputTail = i13 + 1;
    }

    private void _writeQuotedInt(int i10) throws IOException {
        if (this._outputTail + 13 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i11 = this._outputTail;
        int i12 = i11 + 1;
        this._outputTail = i12;
        cArr[i11] = this._quoteChar;
        int outputInt = NumberOutput.outputInt(i10, cArr, i12);
        char[] cArr2 = this._outputBuffer;
        this._outputTail = outputInt + 1;
        cArr2[outputInt] = this._quoteChar;
    }

    private void _writeQuotedLong(long j10) throws IOException {
        if (this._outputTail + 23 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        int i11 = i10 + 1;
        this._outputTail = i11;
        cArr[i10] = this._quoteChar;
        int outputLong = NumberOutput.outputLong(j10, cArr, i11);
        char[] cArr2 = this._outputBuffer;
        this._outputTail = outputLong + 1;
        cArr2[outputLong] = this._quoteChar;
    }

    private void _writeQuotedRaw(String str) throws IOException {
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = this._quoteChar;
        writeRaw(str);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr2[i11] = this._quoteChar;
    }

    private void _writeQuotedShort(short s10) throws IOException {
        if (this._outputTail + 8 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        int i11 = i10 + 1;
        this._outputTail = i11;
        cArr[i10] = this._quoteChar;
        int outputInt = NumberOutput.outputInt(s10, cArr, i11);
        char[] cArr2 = this._outputBuffer;
        this._outputTail = outputInt + 1;
        cArr2[outputInt] = this._quoteChar;
    }

    private void _writeSegment(int i10) throws IOException {
        char[] cArr;
        char c10;
        int[] iArr = this._outputEscapes;
        int length = iArr.length;
        int i11 = 0;
        int i12 = 0;
        while (i11 < i10) {
            do {
                cArr = this._outputBuffer;
                c10 = cArr[i11];
                if (c10 < length && iArr[c10] != 0) {
                    break;
                } else {
                    i11++;
                }
            } while (i11 < i10);
            int i13 = i11 - i12;
            if (i13 > 0) {
                this._writer.write(cArr, i12, i13);
                if (i11 >= i10) {
                    return;
                }
            }
            i11++;
            i12 = _prependOrWriteCharacterEscape(this._outputBuffer, i11, i10, c10, iArr[c10]);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:20:? A[LOOP:1: B:3:0x000e->B:20:?, LOOP_END, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0021 A[EDGE_INSN: B:9:0x0021->B:10:0x0021 BREAK  A[LOOP:1: B:3:0x000e->B:20:?], SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void _writeSegmentASCII(int i10, int i11) throws IOException, JsonGenerationException {
        char[] cArr;
        char c10;
        int[] iArr = this._outputEscapes;
        int min = Math.min(iArr.length, i11 + 1);
        int i12 = 0;
        int i13 = 0;
        int i14 = 0;
        while (i12 < i10) {
            while (true) {
                cArr = this._outputBuffer;
                c10 = cArr[i12];
                if (c10 < min) {
                    i14 = iArr[c10];
                    if (i14 != 0) {
                        break;
                    }
                    i12++;
                    if (i12 < i10) {
                        break;
                    }
                } else {
                    if (c10 > i11) {
                        i14 = -1;
                        break;
                    }
                    i12++;
                    if (i12 < i10) {
                    }
                }
            }
            int i15 = i12 - i13;
            if (i15 > 0) {
                this._writer.write(cArr, i13, i15);
                if (i12 >= i10) {
                    return;
                }
            }
            i12++;
            i13 = _prependOrWriteCharacterEscape(this._outputBuffer, i12, i10, c10, i14);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0035 A[EDGE_INSN: B:12:0x0035->B:13:0x0035 BREAK  A[LOOP:1: B:6:0x0018->B:23:?], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:23:? A[LOOP:1: B:6:0x0018->B:23:?, LOOP_END, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void _writeSegmentCustom(int i10) throws IOException, JsonGenerationException {
        char c10;
        int[] iArr = this._outputEscapes;
        int i11 = this._maximumNonEscapedChar;
        if (i11 < 1) {
            i11 = 65535;
        }
        int min = Math.min(iArr.length, i11 + 1);
        CharacterEscapes characterEscapes = this._characterEscapes;
        int i12 = 0;
        int i13 = 0;
        int i14 = 0;
        while (i12 < i10) {
            while (true) {
                c10 = this._outputBuffer[i12];
                if (c10 < min) {
                    i14 = iArr[c10];
                    if (i14 != 0) {
                        break;
                    }
                    i12++;
                    if (i12 < i10) {
                        break;
                    }
                } else {
                    if (c10 > i11) {
                        i14 = -1;
                        break;
                    }
                    SerializableString escapeSequence = characterEscapes.getEscapeSequence(c10);
                    this._currentEscape = escapeSequence;
                    if (escapeSequence != null) {
                        i14 = -2;
                        break;
                    }
                    i12++;
                    if (i12 < i10) {
                    }
                }
            }
            int i15 = i12 - i13;
            if (i15 > 0) {
                this._writer.write(this._outputBuffer, i13, i15);
                if (i12 >= i10) {
                    return;
                }
            }
            i12++;
            i13 = _prependOrWriteCharacterEscape(this._outputBuffer, i12, i10, c10, i14);
        }
    }

    private void _writeString(String str) throws IOException {
        int length = str.length();
        int i10 = this._outputEnd;
        if (length > i10) {
            _writeLongString(str);
            return;
        }
        if (this._outputTail + length > i10) {
            _flushBuffer();
        }
        str.getChars(0, length, this._outputBuffer, this._outputTail);
        if (this._characterEscapes != null) {
            _writeStringCustom(length);
            return;
        }
        int i11 = this._maximumNonEscapedChar;
        if (i11 != 0) {
            _writeStringASCII(length, i11);
        } else {
            _writeString2(length);
        }
    }

    private void _writeString2(SerializableString serializableString) throws IOException {
        char[] asQuotedChars = serializableString.asQuotedChars();
        int length = asQuotedChars.length;
        if (length < 32) {
            if (length > this._outputEnd - this._outputTail) {
                _flushBuffer();
            }
            System.arraycopy(asQuotedChars, 0, this._outputBuffer, this._outputTail, length);
            this._outputTail += length;
        } else {
            _flushBuffer();
            this._writer.write(asQuotedChars, 0, length);
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = this._quoteChar;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0025  */
    /* JADX WARN: Removed duplicated region for block: B:20:0x002a A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void _writeStringASCII(int i10, int i11) throws IOException, JsonGenerationException {
        int i12;
        int i13;
        int i14;
        int i15 = this._outputTail + i10;
        int[] iArr = this._outputEscapes;
        int min = Math.min(iArr.length, i11 + 1);
        while (this._outputTail < i15) {
            do {
                char[] cArr = this._outputBuffer;
                int i16 = this._outputTail;
                char c10 = cArr[i16];
                if (c10 < min) {
                    i12 = iArr[c10];
                    if (i12 != 0) {
                        int i17 = this._outputHead;
                        i13 = i16 - i17;
                        if (i13 <= 0) {
                            this._writer.write(cArr, i17, i13);
                        }
                        this._outputTail++;
                        _prependOrWriteCharacterEscape(c10, i12);
                    }
                    i14 = i16 + 1;
                    this._outputTail = i14;
                } else {
                    if (c10 > i11) {
                        i12 = -1;
                        int i172 = this._outputHead;
                        i13 = i16 - i172;
                        if (i13 <= 0) {
                        }
                        this._outputTail++;
                        _prependOrWriteCharacterEscape(c10, i12);
                    }
                    i14 = i16 + 1;
                    this._outputTail = i14;
                }
            } while (i14 < i15);
            return;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x003b  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0042 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void _writeStringCustom(int i10) throws IOException, JsonGenerationException {
        int i11;
        int i12;
        int i13;
        int i14 = this._outputTail + i10;
        int[] iArr = this._outputEscapes;
        int i15 = this._maximumNonEscapedChar;
        if (i15 < 1) {
            i15 = 65535;
        }
        int min = Math.min(iArr.length, i15 + 1);
        CharacterEscapes characterEscapes = this._characterEscapes;
        while (this._outputTail < i14) {
            do {
                char c10 = this._outputBuffer[this._outputTail];
                if (c10 < min) {
                    i11 = iArr[c10];
                    if (i11 != 0) {
                        int i16 = this._outputTail;
                        int i17 = this._outputHead;
                        i12 = i16 - i17;
                        if (i12 <= 0) {
                            this._writer.write(this._outputBuffer, i17, i12);
                        }
                        this._outputTail++;
                        _prependOrWriteCharacterEscape(c10, i11);
                    }
                    i13 = this._outputTail + 1;
                    this._outputTail = i13;
                } else {
                    if (c10 > i15) {
                        i11 = -1;
                    } else {
                        SerializableString escapeSequence = characterEscapes.getEscapeSequence(c10);
                        this._currentEscape = escapeSequence;
                        if (escapeSequence != null) {
                            i11 = -2;
                        }
                        i13 = this._outputTail + 1;
                        this._outputTail = i13;
                    }
                    int i162 = this._outputTail;
                    int i172 = this._outputHead;
                    i12 = i162 - i172;
                    if (i12 <= 0) {
                    }
                    this._outputTail++;
                    _prependOrWriteCharacterEscape(c10, i11);
                }
            } while (i13 < i14);
            return;
        }
    }

    private void writeRawLong(String str) throws IOException {
        int i10 = this._outputEnd;
        int i11 = this._outputTail;
        int i12 = i10 - i11;
        str.getChars(0, i12, this._outputBuffer, i11);
        this._outputTail += i12;
        _flushBuffer();
        int length = str.length() - i12;
        while (true) {
            int i13 = this._outputEnd;
            if (length <= i13) {
                str.getChars(i12, i12 + length, this._outputBuffer, 0);
                this._outputHead = 0;
                this._outputTail = length;
                return;
            } else {
                int i14 = i12 + i13;
                str.getChars(i12, i14, this._outputBuffer, 0);
                this._outputHead = 0;
                this._outputTail = i13;
                _flushBuffer();
                length -= i13;
                i12 = i14;
            }
        }
    }

    protected void _flushBuffer() throws IOException {
        int i10 = this._outputTail;
        int i11 = this._outputHead;
        int i12 = i10 - i11;
        if (i12 > 0) {
            this._outputHead = 0;
            this._outputTail = 0;
            this._writer.write(this._outputBuffer, i11, i12);
        }
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase
    protected void _releaseBuffers() {
        char[] cArr = this._outputBuffer;
        if (cArr != null) {
            this._outputBuffer = null;
            this._ioContext.releaseConcatBuffer(cArr);
        }
        char[] cArr2 = this._copyBuffer;
        if (cArr2 != null) {
            this._copyBuffer = null;
            this._ioContext.releaseNameCopyBuffer(cArr2);
        }
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase
    protected final void _verifyValueWrite(String str) throws IOException {
        char c10;
        int writeValue = this._writeContext.writeValue();
        if (this._cfgPrettyPrinter != null) {
            _verifyPrettyValueWrite(str, writeValue);
            return;
        }
        if (writeValue == 1) {
            c10 = ',';
        } else {
            if (writeValue != 2) {
                if (writeValue != 3) {
                    if (writeValue != 5) {
                        return;
                    }
                    _reportCantWriteValueExpectName(str);
                    return;
                } else {
                    SerializableString serializableString = this._rootValueSeparator;
                    if (serializableString != null) {
                        writeRaw(serializableString.getValue());
                        return;
                    }
                    return;
                }
            }
            c10 = ':';
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = c10;
    }

    protected final void _writeBinary(Base64Variant base64Variant, byte[] bArr, int i10, int i11) throws IOException, JsonGenerationException {
        int i12 = i11 - 3;
        int i13 = this._outputEnd - 6;
        int maxLineLength = base64Variant.getMaxLineLength() >> 2;
        while (i10 <= i12) {
            if (this._outputTail > i13) {
                _flushBuffer();
            }
            int i14 = i10 + 1;
            int i15 = i14 + 1;
            int i16 = ((bArr[i10] << 8) | (bArr[i14] & 255)) << 8;
            int i17 = i15 + 1;
            int encodeBase64Chunk = base64Variant.encodeBase64Chunk(i16 | (bArr[i15] & 255), this._outputBuffer, this._outputTail);
            this._outputTail = encodeBase64Chunk;
            maxLineLength--;
            if (maxLineLength <= 0) {
                char[] cArr = this._outputBuffer;
                int i18 = encodeBase64Chunk + 1;
                cArr[encodeBase64Chunk] = '\\';
                this._outputTail = i18 + 1;
                cArr[i18] = 'n';
                maxLineLength = base64Variant.getMaxLineLength() >> 2;
            }
            i10 = i17;
        }
        int i19 = i11 - i10;
        if (i19 > 0) {
            if (this._outputTail > i13) {
                _flushBuffer();
            }
            int i20 = i10 + 1;
            int i21 = bArr[i10] << 16;
            if (i19 == 2) {
                i21 |= (bArr[i20] & 255) << 8;
            }
            this._outputTail = base64Variant.encodeBase64Partial(i21, i19, this._outputBuffer, this._outputTail);
        }
    }

    protected final void _writeFieldName(String str, boolean z10) throws IOException {
        if (this._cfgPrettyPrinter != null) {
            _writePPFieldName(str, z10);
            return;
        }
        if (this._outputTail + 1 >= this._outputEnd) {
            _flushBuffer();
        }
        if (z10) {
            char[] cArr = this._outputBuffer;
            int i10 = this._outputTail;
            this._outputTail = i10 + 1;
            cArr[i10] = ',';
        }
        if (this._cfgUnqNames) {
            _writeString(str);
            return;
        }
        char[] cArr2 = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr2[i11] = this._quoteChar;
        _writeString(str);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr3 = this._outputBuffer;
        int i12 = this._outputTail;
        this._outputTail = i12 + 1;
        cArr3[i12] = this._quoteChar;
    }

    protected final void _writePPFieldName(String str, boolean z10) throws IOException {
        if (z10) {
            this._cfgPrettyPrinter.writeObjectEntrySeparator(this);
        } else {
            this._cfgPrettyPrinter.beforeObjectEntries(this);
        }
        if (this._cfgUnqNames) {
            _writeString(str);
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = this._quoteChar;
        _writeString(str);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr2[i11] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public boolean canWriteFormattedNumbers() {
        return true;
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.JsonGenerator, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        super.close();
        if (this._outputBuffer != null && isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT)) {
            while (true) {
                JsonStreamContext outputContext = getOutputContext();
                if (!outputContext.inArray()) {
                    if (!outputContext.inObject()) {
                        break;
                    } else {
                        writeEndObject();
                    }
                } else {
                    writeEndArray();
                }
            }
        }
        _flushBuffer();
        this._outputHead = 0;
        this._outputTail = 0;
        if (this._writer != null) {
            if (this._ioContext.isResourceManaged() || isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) {
                this._writer.close();
            } else if (isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)) {
                this._writer.flush();
            }
        }
        _releaseBuffers();
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.JsonGenerator, java.io.Flushable
    public void flush() throws IOException {
        _flushBuffer();
        if (this._writer == null || !isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)) {
            return;
        }
        this._writer.flush();
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public int getOutputBuffered() {
        return Math.max(0, this._outputTail - this._outputHead);
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public Object getOutputTarget() {
        return this._writer;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeBinary(Base64Variant base64Variant, byte[] bArr, int i10, int i11) throws IOException, JsonGenerationException {
        _verifyValueWrite("write a binary value");
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i12 = this._outputTail;
        this._outputTail = i12 + 1;
        cArr[i12] = this._quoteChar;
        _writeBinary(base64Variant, bArr, i10, i11 + i10);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i13 = this._outputTail;
        this._outputTail = i13 + 1;
        cArr2[i13] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeBoolean(boolean z10) throws IOException {
        int i10;
        _verifyValueWrite("write a boolean value");
        if (this._outputTail + 5 >= this._outputEnd) {
            _flushBuffer();
        }
        int i11 = this._outputTail;
        char[] cArr = this._outputBuffer;
        if (z10) {
            cArr[i11] = 't';
            int i12 = i11 + 1;
            cArr[i12] = 'r';
            int i13 = i12 + 1;
            cArr[i13] = 'u';
            i10 = i13 + 1;
            cArr[i10] = 'e';
        } else {
            cArr[i11] = 'f';
            int i14 = i11 + 1;
            cArr[i14] = 'a';
            int i15 = i14 + 1;
            cArr[i15] = 'l';
            int i16 = i15 + 1;
            cArr[i16] = 's';
            i10 = i16 + 1;
            cArr[i10] = 'e';
        }
        this._outputTail = i10 + 1;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeEndArray() throws IOException {
        if (!this._writeContext.inArray()) {
            _reportError("Current context not Array but " + this._writeContext.typeDesc());
        }
        PrettyPrinter prettyPrinter = this._cfgPrettyPrinter;
        if (prettyPrinter != null) {
            prettyPrinter.writeEndArray(this, this._writeContext.getEntryCount());
        } else {
            if (this._outputTail >= this._outputEnd) {
                _flushBuffer();
            }
            char[] cArr = this._outputBuffer;
            int i10 = this._outputTail;
            this._outputTail = i10 + 1;
            cArr[i10] = ']';
        }
        this._writeContext = this._writeContext.clearAndGetParent();
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeEndObject() throws IOException {
        if (!this._writeContext.inObject()) {
            _reportError("Current context not Object but " + this._writeContext.typeDesc());
        }
        PrettyPrinter prettyPrinter = this._cfgPrettyPrinter;
        if (prettyPrinter != null) {
            prettyPrinter.writeEndObject(this, this._writeContext.getEntryCount());
        } else {
            if (this._outputTail >= this._outputEnd) {
                _flushBuffer();
            }
            char[] cArr = this._outputBuffer;
            int i10 = this._outputTail;
            this._outputTail = i10 + 1;
            cArr[i10] = '}';
        }
        this._writeContext = this._writeContext.clearAndGetParent();
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeFieldName(String str) throws IOException {
        int writeFieldName = this._writeContext.writeFieldName(str);
        if (writeFieldName == 4) {
            _reportError("Can not write a field name, expecting a value");
        }
        _writeFieldName(str, writeFieldName == 1);
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNull() throws IOException {
        _verifyValueWrite("write a null");
        _writeNull();
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(short s10) throws IOException {
        _verifyValueWrite("write a number");
        if (this._cfgNumbersAsStrings) {
            _writeQuotedShort(s10);
            return;
        }
        if (this._outputTail + 6 >= this._outputEnd) {
            _flushBuffer();
        }
        this._outputTail = NumberOutput.outputInt(s10, this._outputBuffer, this._outputTail);
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeRaw(String str) throws IOException {
        int length = str.length();
        int i10 = this._outputEnd - this._outputTail;
        if (i10 == 0) {
            _flushBuffer();
            i10 = this._outputEnd - this._outputTail;
        }
        if (i10 >= length) {
            str.getChars(0, length, this._outputBuffer, this._outputTail);
            this._outputTail += length;
        } else {
            writeRawLong(str);
        }
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeRawUTF8String(byte[] bArr, int i10, int i11) throws IOException {
        _reportUnsupportedOperation();
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeStartArray() throws IOException {
        _verifyValueWrite("start an array");
        this._writeContext = this._writeContext.createChildArrayContext();
        PrettyPrinter prettyPrinter = this._cfgPrettyPrinter;
        if (prettyPrinter != null) {
            prettyPrinter.writeStartArray(this);
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = '[';
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeStartObject() throws IOException {
        _verifyValueWrite("start an object");
        this._writeContext = this._writeContext.createChildObjectContext();
        PrettyPrinter prettyPrinter = this._cfgPrettyPrinter;
        if (prettyPrinter != null) {
            prettyPrinter.writeStartObject(this);
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = '{';
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeString(String str) throws IOException {
        _verifyValueWrite("write a string");
        if (str == null) {
            _writeNull();
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = this._quoteChar;
        _writeString(str);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr2[i11] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeUTF8String(byte[] bArr, int i10, int i11) throws IOException {
        _reportUnsupportedOperation();
    }

    public WriterBasedJsonGenerator(IOContext iOContext, int i10, ObjectCodec objectCodec, Writer writer, char c10) {
        super(iOContext, i10, objectCodec);
        this._writer = writer;
        char[] allocConcatBuffer = iOContext.allocConcatBuffer();
        this._outputBuffer = allocConcatBuffer;
        this._outputEnd = allocConcatBuffer.length;
        this._quoteChar = c10;
        if (c10 != '\"') {
            this._outputEscapes = CharTypes.get7BitOutputEscapes(c10);
        }
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.JsonGenerator
    public void writeFieldName(SerializableString serializableString) throws IOException {
        int writeFieldName = this._writeContext.writeFieldName(serializableString.getValue());
        if (writeFieldName == 4) {
            _reportError("Can not write a field name, expecting a value");
        }
        _writeFieldName(serializableString, writeFieldName == 1);
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(int i10) throws IOException {
        _verifyValueWrite("write a number");
        if (this._cfgNumbersAsStrings) {
            _writeQuotedInt(i10);
            return;
        }
        if (this._outputTail + 11 >= this._outputEnd) {
            _flushBuffer();
        }
        this._outputTail = NumberOutput.outputInt(i10, this._outputBuffer, this._outputTail);
    }

    private void _writeQuotedRaw(char[] cArr, int i10, int i11) throws IOException {
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i12 = this._outputTail;
        this._outputTail = i12 + 1;
        cArr2[i12] = this._quoteChar;
        writeRaw(cArr, i10, i11);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr3 = this._outputBuffer;
        int i13 = this._outputTail;
        this._outputTail = i13 + 1;
        cArr3[i13] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeRaw(String str, int i10, int i11) throws IOException {
        int i12 = this._outputEnd - this._outputTail;
        if (i12 < i11) {
            _flushBuffer();
            i12 = this._outputEnd - this._outputTail;
        }
        if (i12 >= i11) {
            str.getChars(i10, i10 + i11, this._outputBuffer, this._outputTail);
            this._outputTail += i11;
        } else {
            writeRawLong(str.substring(i10, i11 + i10));
        }
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeStartArray(int i10) throws IOException {
        _verifyValueWrite("start an array");
        this._writeContext = this._writeContext.createChildArrayContext();
        PrettyPrinter prettyPrinter = this._cfgPrettyPrinter;
        if (prettyPrinter != null) {
            prettyPrinter.writeStartArray(this);
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr[i11] = '[';
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.JsonGenerator
    public void writeStartObject(Object obj) throws IOException {
        _verifyValueWrite("start an object");
        this._writeContext = this._writeContext.createChildObjectContext(obj);
        PrettyPrinter prettyPrinter = this._cfgPrettyPrinter;
        if (prettyPrinter != null) {
            prettyPrinter.writeStartObject(this);
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = '{';
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.JsonGenerator
    public int writeBinary(Base64Variant base64Variant, InputStream inputStream, int i10) throws IOException, JsonGenerationException {
        _verifyValueWrite("write a binary value");
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr[i11] = this._quoteChar;
        byte[] allocBase64Buffer = this._ioContext.allocBase64Buffer();
        try {
            if (i10 < 0) {
                i10 = _writeBinary(base64Variant, inputStream, allocBase64Buffer);
            } else {
                int _writeBinary = _writeBinary(base64Variant, inputStream, allocBase64Buffer, i10);
                if (_writeBinary > 0) {
                    _reportError("Too few bytes available: missing " + _writeBinary + " bytes (out of " + i10 + ")");
                }
            }
            this._ioContext.releaseBase64Buffer(allocBase64Buffer);
            if (this._outputTail >= this._outputEnd) {
                _flushBuffer();
            }
            char[] cArr2 = this._outputBuffer;
            int i12 = this._outputTail;
            this._outputTail = i12 + 1;
            cArr2[i12] = this._quoteChar;
            return i10;
        } catch (Throwable th2) {
            this._ioContext.releaseBase64Buffer(allocBase64Buffer);
            throw th2;
        }
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeString(Reader reader, int i10) throws IOException {
        _verifyValueWrite("write a string");
        if (reader == null) {
            _reportError("null reader");
        }
        int i11 = i10 >= 0 ? i10 : Api.BaseClientBuilder.API_PRIORITY_OTHER;
        if (this._outputTail + i10 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i12 = this._outputTail;
        this._outputTail = i12 + 1;
        cArr[i12] = this._quoteChar;
        char[] _allocateCopyBuffer = _allocateCopyBuffer();
        while (i11 > 0) {
            int read = reader.read(_allocateCopyBuffer, 0, Math.min(i11, _allocateCopyBuffer.length));
            if (read <= 0) {
                break;
            }
            if (this._outputTail + i10 >= this._outputEnd) {
                _flushBuffer();
            }
            _writeString(_allocateCopyBuffer, 0, read);
            i11 -= read;
        }
        if (this._outputTail + i10 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i13 = this._outputTail;
        this._outputTail = i13 + 1;
        cArr2[i13] = this._quoteChar;
        if (i11 <= 0 || i10 < 0) {
            return;
        }
        _reportError("Didn't read enough from reader");
    }

    private void _writeString(char[] cArr, int i10, int i11) throws IOException {
        if (this._characterEscapes != null) {
            _writeStringCustom(cArr, i10, i11);
            return;
        }
        int i12 = this._maximumNonEscapedChar;
        if (i12 != 0) {
            _writeStringASCII(cArr, i10, i11, i12);
            return;
        }
        int i13 = i11 + i10;
        int[] iArr = this._outputEscapes;
        int length = iArr.length;
        while (i10 < i13) {
            int i14 = i10;
            do {
                char c10 = cArr[i14];
                if (c10 < length && iArr[c10] != 0) {
                    break;
                } else {
                    i14++;
                }
            } while (i14 < i13);
            int i15 = i14 - i10;
            if (i15 < 32) {
                if (this._outputTail + i15 > this._outputEnd) {
                    _flushBuffer();
                }
                if (i15 > 0) {
                    System.arraycopy(cArr, i10, this._outputBuffer, this._outputTail, i15);
                    this._outputTail += i15;
                }
            } else {
                _flushBuffer();
                this._writer.write(cArr, i10, i15);
            }
            if (i14 >= i13) {
                return;
            }
            i10 = i14 + 1;
            char c11 = cArr[i14];
            _appendCharacterEscape(c11, iArr[c11]);
        }
    }

    private void _writeString2(int i10) throws IOException {
        int i11;
        int i12 = this._outputTail + i10;
        int[] iArr = this._outputEscapes;
        int length = iArr.length;
        while (this._outputTail < i12) {
            do {
                char[] cArr = this._outputBuffer;
                int i13 = this._outputTail;
                char c10 = cArr[i13];
                if (c10 < length && iArr[c10] != 0) {
                    int i14 = this._outputHead;
                    int i15 = i13 - i14;
                    if (i15 > 0) {
                        this._writer.write(cArr, i14, i15);
                    }
                    char[] cArr2 = this._outputBuffer;
                    int i16 = this._outputTail;
                    this._outputTail = i16 + 1;
                    char c11 = cArr2[i16];
                    _prependOrWriteCharacterEscape(c11, iArr[c11]);
                } else {
                    i11 = i13 + 1;
                    this._outputTail = i11;
                }
            } while (i11 < i12);
            return;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:10:0x001f A[EDGE_INSN: B:10:0x001f->B:11:0x001f BREAK  A[LOOP:1: B:4:0x000e->B:24:?], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:24:? A[LOOP:1: B:4:0x000e->B:24:?, LOOP_END, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void _writeStringASCII(char[] cArr, int i10, int i11, int i12) throws IOException, JsonGenerationException {
        char c10;
        int i13 = i11 + i10;
        int[] iArr = this._outputEscapes;
        int min = Math.min(iArr.length, i12 + 1);
        int i14 = 0;
        while (i10 < i13) {
            int i15 = i10;
            while (true) {
                c10 = cArr[i15];
                if (c10 < min) {
                    i14 = iArr[c10];
                    if (i14 != 0) {
                        break;
                    }
                    i15++;
                    if (i15 < i13) {
                        break;
                    }
                } else {
                    if (c10 > i12) {
                        i14 = -1;
                        break;
                    }
                    i15++;
                    if (i15 < i13) {
                    }
                }
            }
            int i16 = i15 - i10;
            if (i16 < 32) {
                if (this._outputTail + i16 > this._outputEnd) {
                    _flushBuffer();
                }
                if (i16 > 0) {
                    System.arraycopy(cArr, i10, this._outputBuffer, this._outputTail, i16);
                    this._outputTail += i16;
                }
            } else {
                _flushBuffer();
                this._writer.write(cArr, i10, i16);
            }
            if (i15 >= i13) {
                return;
            }
            i10 = i15 + 1;
            _appendCharacterEscape(c10, i14);
        }
    }

    protected final void _writePPFieldName(SerializableString serializableString, boolean z10) throws IOException {
        if (z10) {
            this._cfgPrettyPrinter.writeObjectEntrySeparator(this);
        } else {
            this._cfgPrettyPrinter.beforeObjectEntries(this);
        }
        char[] asQuotedChars = serializableString.asQuotedChars();
        if (this._cfgUnqNames) {
            writeRaw(asQuotedChars, 0, asQuotedChars.length);
            return;
        }
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = this._quoteChar;
        writeRaw(asQuotedChars, 0, asQuotedChars.length);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i11 = this._outputTail;
        this._outputTail = i11 + 1;
        cArr2[i11] = this._quoteChar;
    }

    protected final void _writeFieldName(SerializableString serializableString, boolean z10) throws IOException {
        if (this._cfgPrettyPrinter != null) {
            _writePPFieldName(serializableString, z10);
            return;
        }
        if (this._outputTail + 1 >= this._outputEnd) {
            _flushBuffer();
        }
        if (z10) {
            char[] cArr = this._outputBuffer;
            int i10 = this._outputTail;
            this._outputTail = i10 + 1;
            cArr[i10] = ',';
        }
        if (this._cfgUnqNames) {
            char[] asQuotedChars = serializableString.asQuotedChars();
            writeRaw(asQuotedChars, 0, asQuotedChars.length);
            return;
        }
        char[] cArr2 = this._outputBuffer;
        int i11 = this._outputTail;
        int i12 = i11 + 1;
        this._outputTail = i12;
        cArr2[i11] = this._quoteChar;
        int appendQuoted = serializableString.appendQuoted(cArr2, i12);
        if (appendQuoted < 0) {
            _writeFieldNameTail(serializableString);
            return;
        }
        int i13 = this._outputTail + appendQuoted;
        this._outputTail = i13;
        if (i13 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr3 = this._outputBuffer;
        int i14 = this._outputTail;
        this._outputTail = i14 + 1;
        cArr3[i14] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(long j10) throws IOException {
        _verifyValueWrite("write a number");
        if (this._cfgNumbersAsStrings) {
            _writeQuotedLong(j10);
            return;
        }
        if (this._outputTail + 21 >= this._outputEnd) {
            _flushBuffer();
        }
        this._outputTail = NumberOutput.outputLong(j10, this._outputBuffer, this._outputTail);
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeRaw(SerializableString serializableString) throws IOException {
        int appendUnquoted = serializableString.appendUnquoted(this._outputBuffer, this._outputTail);
        if (appendUnquoted < 0) {
            writeRaw(serializableString.getValue());
        } else {
            this._outputTail += appendUnquoted;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0033 A[EDGE_INSN: B:13:0x0033->B:14:0x0033 BREAK  A[LOOP:1: B:7:0x0018->B:27:?], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:27:? A[LOOP:1: B:7:0x0018->B:27:?, LOOP_END, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void _writeStringCustom(char[] cArr, int i10, int i11) throws IOException, JsonGenerationException {
        char c10;
        int i12 = i11 + i10;
        int[] iArr = this._outputEscapes;
        int i13 = this._maximumNonEscapedChar;
        if (i13 < 1) {
            i13 = 65535;
        }
        int min = Math.min(iArr.length, i13 + 1);
        CharacterEscapes characterEscapes = this._characterEscapes;
        int i14 = 0;
        while (i10 < i12) {
            int i15 = i10;
            while (true) {
                c10 = cArr[i15];
                if (c10 < min) {
                    i14 = iArr[c10];
                    if (i14 != 0) {
                        break;
                    }
                    i15++;
                    if (i15 < i12) {
                        break;
                    }
                } else {
                    if (c10 > i13) {
                        i14 = -1;
                        break;
                    }
                    SerializableString escapeSequence = characterEscapes.getEscapeSequence(c10);
                    this._currentEscape = escapeSequence;
                    if (escapeSequence != null) {
                        i14 = -2;
                        break;
                    }
                    i15++;
                    if (i15 < i12) {
                    }
                }
            }
            int i16 = i15 - i10;
            if (i16 < 32) {
                if (this._outputTail + i16 > this._outputEnd) {
                    _flushBuffer();
                }
                if (i16 > 0) {
                    System.arraycopy(cArr, i10, this._outputBuffer, this._outputTail, i16);
                    this._outputTail += i16;
                }
            } else {
                _flushBuffer();
                this._writer.write(cArr, i10, i16);
            }
            if (i15 >= i12) {
                return;
            }
            i10 = i15 + 1;
            _appendCharacterEscape(c10, i14);
        }
    }

    protected final int _writeBinary(Base64Variant base64Variant, InputStream inputStream, byte[] bArr, int i10) throws IOException, JsonGenerationException {
        int _readMore;
        int i11 = this._outputEnd - 6;
        int i12 = 2;
        int maxLineLength = base64Variant.getMaxLineLength() >> 2;
        int i13 = -3;
        int i14 = 0;
        int i15 = 0;
        while (true) {
            if (i10 <= 2) {
                break;
            }
            if (i14 > i13) {
                i15 = _readMore(inputStream, bArr, i14, i15, i10);
                if (i15 < 3) {
                    i14 = 0;
                    break;
                }
                i13 = i15 - 3;
                i14 = 0;
            }
            if (this._outputTail > i11) {
                _flushBuffer();
            }
            int i16 = i14 + 1;
            int i17 = bArr[i14] << 8;
            int i18 = i16 + 1;
            i14 = i18 + 1;
            i10 -= 3;
            int encodeBase64Chunk = base64Variant.encodeBase64Chunk((((bArr[i16] & 255) | i17) << 8) | (bArr[i18] & 255), this._outputBuffer, this._outputTail);
            this._outputTail = encodeBase64Chunk;
            maxLineLength--;
            if (maxLineLength <= 0) {
                char[] cArr = this._outputBuffer;
                int i19 = encodeBase64Chunk + 1;
                cArr[encodeBase64Chunk] = '\\';
                this._outputTail = i19 + 1;
                cArr[i19] = 'n';
                maxLineLength = base64Variant.getMaxLineLength() >> 2;
            }
        }
        if (i10 <= 0 || (_readMore = _readMore(inputStream, bArr, i14, i15, i10)) <= 0) {
            return i10;
        }
        if (this._outputTail > i11) {
            _flushBuffer();
        }
        int i20 = bArr[0] << 16;
        if (1 < _readMore) {
            i20 |= (bArr[1] & 255) << 8;
        } else {
            i12 = 1;
        }
        this._outputTail = base64Variant.encodeBase64Partial(i20, i12, this._outputBuffer, this._outputTail);
        return i10 - i12;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeRaw(char[] cArr, int i10, int i11) throws IOException {
        if (i11 < 32) {
            if (i11 > this._outputEnd - this._outputTail) {
                _flushBuffer();
            }
            System.arraycopy(cArr, i10, this._outputBuffer, this._outputTail, i11);
            this._outputTail += i11;
            return;
        }
        _flushBuffer();
        this._writer.write(cArr, i10, i11);
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(BigInteger bigInteger) throws IOException {
        _verifyValueWrite("write a number");
        if (bigInteger == null) {
            _writeNull();
        } else if (this._cfgNumbersAsStrings) {
            _writeQuotedRaw(bigInteger.toString());
        } else {
            writeRaw(bigInteger.toString());
        }
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeRaw(char c10) throws IOException {
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        this._outputTail = i10 + 1;
        cArr[i10] = c10;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(double d10) throws IOException {
        if (!this._cfgNumbersAsStrings && (!NumberOutput.notFinite(d10) || !isEnabled(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS))) {
            _verifyValueWrite("write a number");
            writeRaw(String.valueOf(d10));
        } else {
            writeString(String.valueOf(d10));
        }
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeString(char[] cArr, int i10, int i11) throws IOException {
        _verifyValueWrite("write a string");
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i12 = this._outputTail;
        this._outputTail = i12 + 1;
        cArr2[i12] = this._quoteChar;
        _writeString(cArr, i10, i11);
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr3 = this._outputBuffer;
        int i13 = this._outputTail;
        this._outputTail = i13 + 1;
        cArr3[i13] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(float f10) throws IOException {
        if (!this._cfgNumbersAsStrings && (!NumberOutput.notFinite(f10) || !isEnabled(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS))) {
            _verifyValueWrite("write a number");
            writeRaw(String.valueOf(f10));
        } else {
            writeString(String.valueOf(f10));
        }
    }

    @Override // com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.JsonGenerator
    public void writeString(SerializableString serializableString) throws IOException {
        _verifyValueWrite("write a string");
        if (this._outputTail >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr = this._outputBuffer;
        int i10 = this._outputTail;
        int i11 = i10 + 1;
        this._outputTail = i11;
        cArr[i10] = this._quoteChar;
        int appendQuoted = serializableString.appendQuoted(cArr, i11);
        if (appendQuoted < 0) {
            _writeString2(serializableString);
            return;
        }
        int i12 = this._outputTail + appendQuoted;
        this._outputTail = i12;
        if (i12 >= this._outputEnd) {
            _flushBuffer();
        }
        char[] cArr2 = this._outputBuffer;
        int i13 = this._outputTail;
        this._outputTail = i13 + 1;
        cArr2[i13] = this._quoteChar;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(BigDecimal bigDecimal) throws IOException {
        _verifyValueWrite("write a number");
        if (bigDecimal == null) {
            _writeNull();
        } else if (this._cfgNumbersAsStrings) {
            _writeQuotedRaw(_asString(bigDecimal));
        } else {
            writeRaw(_asString(bigDecimal));
        }
    }

    protected final int _writeBinary(Base64Variant base64Variant, InputStream inputStream, byte[] bArr) throws IOException, JsonGenerationException {
        int i10 = this._outputEnd - 6;
        int i11 = 2;
        int maxLineLength = base64Variant.getMaxLineLength() >> 2;
        int i12 = -3;
        int i13 = 0;
        int i14 = 0;
        int i15 = 0;
        while (true) {
            if (i13 > i12) {
                i14 = _readMore(inputStream, bArr, i13, i14, bArr.length);
                if (i14 < 3) {
                    break;
                }
                i12 = i14 - 3;
                i13 = 0;
            }
            if (this._outputTail > i10) {
                _flushBuffer();
            }
            int i16 = i13 + 1;
            int i17 = bArr[i13] << 8;
            int i18 = i16 + 1;
            i13 = i18 + 1;
            i15 += 3;
            int encodeBase64Chunk = base64Variant.encodeBase64Chunk((((bArr[i16] & 255) | i17) << 8) | (bArr[i18] & 255), this._outputBuffer, this._outputTail);
            this._outputTail = encodeBase64Chunk;
            maxLineLength--;
            if (maxLineLength <= 0) {
                char[] cArr = this._outputBuffer;
                int i19 = encodeBase64Chunk + 1;
                cArr[encodeBase64Chunk] = '\\';
                this._outputTail = i19 + 1;
                cArr[i19] = 'n';
                maxLineLength = base64Variant.getMaxLineLength() >> 2;
            }
        }
        if (i14 <= 0) {
            return i15;
        }
        if (this._outputTail > i10) {
            _flushBuffer();
        }
        int i20 = bArr[0] << 16;
        if (1 < i14) {
            i20 |= (bArr[1] & 255) << 8;
        } else {
            i11 = 1;
        }
        int i21 = i15 + i11;
        this._outputTail = base64Variant.encodeBase64Partial(i20, i11, this._outputBuffer, this._outputTail);
        return i21;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(String str) throws IOException {
        _verifyValueWrite("write a number");
        if (this._cfgNumbersAsStrings) {
            _writeQuotedRaw(str);
        } else {
            writeRaw(str);
        }
    }

    private int _prependOrWriteCharacterEscape(char[] cArr, int i10, int i11, char c10, int i12) throws IOException, JsonGenerationException {
        String value;
        int i13;
        if (i12 >= 0) {
            if (i10 > 1 && i10 < i11) {
                int i14 = i10 - 2;
                cArr[i14] = '\\';
                cArr[i14 + 1] = (char) i12;
                return i14;
            }
            char[] cArr2 = this._entityBuffer;
            if (cArr2 == null) {
                cArr2 = _allocateEntityBuffer();
            }
            cArr2[1] = (char) i12;
            this._writer.write(cArr2, 0, 2);
            return i10;
        }
        if (i12 == -2) {
            SerializableString serializableString = this._currentEscape;
            if (serializableString == null) {
                value = this._characterEscapes.getEscapeSequence(c10).getValue();
            } else {
                value = serializableString.getValue();
                this._currentEscape = null;
            }
            int length = value.length();
            if (i10 >= length && i10 < i11) {
                int i15 = i10 - length;
                value.getChars(0, length, cArr, i15);
                return i15;
            }
            this._writer.write(value);
            return i10;
        }
        if (i10 > 5 && i10 < i11) {
            int i16 = i10 - 6;
            int i17 = i16 + 1;
            cArr[i16] = '\\';
            int i18 = i17 + 1;
            cArr[i17] = 'u';
            if (c10 > 255) {
                int i19 = (c10 >> '\b') & Constants.MAX_HOST_LENGTH;
                int i20 = i18 + 1;
                char[] cArr3 = HEX_CHARS;
                cArr[i18] = cArr3[i19 >> 4];
                i13 = i20 + 1;
                cArr[i20] = cArr3[i19 & 15];
                c10 = (char) (c10 & 255);
            } else {
                int i21 = i18 + 1;
                cArr[i18] = '0';
                i13 = i21 + 1;
                cArr[i21] = '0';
            }
            int i22 = i13 + 1;
            char[] cArr4 = HEX_CHARS;
            cArr[i13] = cArr4[c10 >> 4];
            cArr[i22] = cArr4[c10 & 15];
            return i22 - 5;
        }
        char[] cArr5 = this._entityBuffer;
        if (cArr5 == null) {
            cArr5 = _allocateEntityBuffer();
        }
        this._outputHead = this._outputTail;
        if (c10 > 255) {
            int i23 = (c10 >> '\b') & Constants.MAX_HOST_LENGTH;
            int i24 = c10 & 255;
            char[] cArr6 = HEX_CHARS;
            cArr5[10] = cArr6[i23 >> 4];
            cArr5[11] = cArr6[i23 & 15];
            cArr5[12] = cArr6[i24 >> 4];
            cArr5[13] = cArr6[i24 & 15];
            this._writer.write(cArr5, 8, 6);
            return i10;
        }
        char[] cArr7 = HEX_CHARS;
        cArr5[6] = cArr7[c10 >> 4];
        cArr5[7] = cArr7[c10 & 15];
        this._writer.write(cArr5, 2, 6);
        return i10;
    }

    @Override // com.fasterxml.jackson.core.JsonGenerator
    public void writeNumber(char[] cArr, int i10, int i11) throws IOException {
        _verifyValueWrite("write a number");
        if (this._cfgNumbersAsStrings) {
            _writeQuotedRaw(cArr, i10, i11);
        } else {
            writeRaw(cArr, i10, i11);
        }
    }
}
