mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-12-02 18:50:21 +01:00
434 lines
13 KiB
Java
434 lines
13 KiB
Java
package org.codehaus.jackson.util;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import org.codehaus.jackson.io.NumberInput;
|
|
import org.codehaus.jackson.util.BufferRecycler;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes11.dex */
|
|
public final class TextBuffer {
|
|
static final int MAX_SEGMENT_LEN = 262144;
|
|
static final int MIN_SEGMENT_LEN = 1000;
|
|
static final char[] NO_CHARS = new char[0];
|
|
private final BufferRecycler _allocator;
|
|
private char[] _currentSegment;
|
|
private int _currentSize;
|
|
private boolean _hasSegments = false;
|
|
private char[] _inputBuffer;
|
|
private int _inputLen;
|
|
private int _inputStart;
|
|
private char[] _resultArray;
|
|
private String _resultString;
|
|
private int _segmentSize;
|
|
private ArrayList<char[]> _segments;
|
|
|
|
public TextBuffer(BufferRecycler bufferRecycler) {
|
|
this._allocator = bufferRecycler;
|
|
}
|
|
|
|
private final char[] _charArray(int i) {
|
|
return new char[i];
|
|
}
|
|
|
|
private char[] buildResultArray() {
|
|
int i;
|
|
String str = this._resultString;
|
|
if (str != null) {
|
|
return str.toCharArray();
|
|
}
|
|
if (this._inputStart >= 0) {
|
|
int i2 = this._inputLen;
|
|
if (i2 < 1) {
|
|
return NO_CHARS;
|
|
}
|
|
char[] _charArray = _charArray(i2);
|
|
System.arraycopy(this._inputBuffer, this._inputStart, _charArray, 0, this._inputLen);
|
|
return _charArray;
|
|
}
|
|
int size = size();
|
|
if (size < 1) {
|
|
return NO_CHARS;
|
|
}
|
|
char[] _charArray2 = _charArray(size);
|
|
ArrayList<char[]> arrayList = this._segments;
|
|
if (arrayList != null) {
|
|
int size2 = arrayList.size();
|
|
i = 0;
|
|
for (int i3 = 0; i3 < size2; i3++) {
|
|
char[] cArr = this._segments.get(i3);
|
|
int length = cArr.length;
|
|
System.arraycopy(cArr, 0, _charArray2, i, length);
|
|
i += length;
|
|
}
|
|
} else {
|
|
i = 0;
|
|
}
|
|
System.arraycopy(this._currentSegment, 0, _charArray2, i, this._currentSize);
|
|
return _charArray2;
|
|
}
|
|
|
|
private final void clearSegments() {
|
|
this._hasSegments = false;
|
|
this._segments.clear();
|
|
this._segmentSize = 0;
|
|
this._currentSize = 0;
|
|
}
|
|
|
|
private void expand(int i) {
|
|
if (this._segments == null) {
|
|
this._segments = new ArrayList<>();
|
|
}
|
|
char[] cArr = this._currentSegment;
|
|
this._hasSegments = true;
|
|
this._segments.add(cArr);
|
|
this._segmentSize += cArr.length;
|
|
int length = cArr.length;
|
|
int i2 = length >> 1;
|
|
if (i2 >= i) {
|
|
i = i2;
|
|
}
|
|
char[] _charArray = _charArray(Math.min(262144, length + i));
|
|
this._currentSize = 0;
|
|
this._currentSegment = _charArray;
|
|
}
|
|
|
|
private final char[] findBuffer(int i) {
|
|
BufferRecycler bufferRecycler = this._allocator;
|
|
return bufferRecycler != null ? bufferRecycler.allocCharBuffer(BufferRecycler.CharBufferType.TEXT_BUFFER, i) : new char[Math.max(i, 1000)];
|
|
}
|
|
|
|
private void unshare(int i) {
|
|
int i2 = this._inputLen;
|
|
this._inputLen = 0;
|
|
char[] cArr = this._inputBuffer;
|
|
this._inputBuffer = null;
|
|
int i3 = this._inputStart;
|
|
this._inputStart = -1;
|
|
int i4 = i + i2;
|
|
char[] cArr2 = this._currentSegment;
|
|
if (cArr2 == null || i4 > cArr2.length) {
|
|
this._currentSegment = findBuffer(i4);
|
|
}
|
|
if (i2 > 0) {
|
|
System.arraycopy(cArr, i3, this._currentSegment, 0, i2);
|
|
}
|
|
this._segmentSize = 0;
|
|
this._currentSize = i2;
|
|
}
|
|
|
|
public void append(String str, int i, int i2) {
|
|
if (this._inputStart >= 0) {
|
|
unshare(i2);
|
|
}
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
char[] cArr = this._currentSegment;
|
|
int length = cArr.length;
|
|
int i3 = this._currentSize;
|
|
int i4 = length - i3;
|
|
if (i4 >= i2) {
|
|
str.getChars(i, i + i2, cArr, i3);
|
|
this._currentSize += i2;
|
|
return;
|
|
}
|
|
if (i4 > 0) {
|
|
int i5 = i + i4;
|
|
str.getChars(i, i5, cArr, i3);
|
|
i2 -= i4;
|
|
i = i5;
|
|
}
|
|
while (true) {
|
|
expand(i2);
|
|
int min = Math.min(this._currentSegment.length, i2);
|
|
int i6 = i + min;
|
|
str.getChars(i, i6, this._currentSegment, 0);
|
|
this._currentSize += min;
|
|
i2 -= min;
|
|
if (i2 <= 0) {
|
|
return;
|
|
} else {
|
|
i = i6;
|
|
}
|
|
}
|
|
}
|
|
|
|
public char[] contentsAsArray() {
|
|
char[] cArr = this._resultArray;
|
|
if (cArr != null) {
|
|
return cArr;
|
|
}
|
|
char[] buildResultArray = buildResultArray();
|
|
this._resultArray = buildResultArray;
|
|
return buildResultArray;
|
|
}
|
|
|
|
public BigDecimal contentsAsDecimal() throws NumberFormatException {
|
|
return this._resultArray != null ? new BigDecimal(this._resultArray) : this._inputStart >= 0 ? new BigDecimal(this._inputBuffer, this._inputStart, this._inputLen) : this._segmentSize == 0 ? new BigDecimal(this._currentSegment, 0, this._currentSize) : new BigDecimal(contentsAsArray());
|
|
}
|
|
|
|
public double contentsAsDouble() throws NumberFormatException {
|
|
return NumberInput.parseDouble(contentsAsString());
|
|
}
|
|
|
|
public String contentsAsString() {
|
|
if (this._resultString == null) {
|
|
char[] cArr = this._resultArray;
|
|
if (cArr != null) {
|
|
this._resultString = new String(cArr);
|
|
} else {
|
|
int i = this._inputStart;
|
|
if (i >= 0) {
|
|
int i2 = this._inputLen;
|
|
if (i2 < 1) {
|
|
this._resultString = "";
|
|
return "";
|
|
}
|
|
this._resultString = new String(this._inputBuffer, i, i2);
|
|
} else {
|
|
int i3 = this._segmentSize;
|
|
int i4 = this._currentSize;
|
|
if (i3 == 0) {
|
|
this._resultString = i4 != 0 ? new String(this._currentSegment, 0, i4) : "";
|
|
} else {
|
|
StringBuilder sb = new StringBuilder(i3 + i4);
|
|
ArrayList<char[]> arrayList = this._segments;
|
|
if (arrayList != null) {
|
|
int size = arrayList.size();
|
|
for (int i5 = 0; i5 < size; i5++) {
|
|
char[] cArr2 = this._segments.get(i5);
|
|
sb.append(cArr2, 0, cArr2.length);
|
|
}
|
|
}
|
|
sb.append(this._currentSegment, 0, this._currentSize);
|
|
this._resultString = sb.toString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return this._resultString;
|
|
}
|
|
|
|
public final char[] emptyAndGetCurrentSegment() {
|
|
this._inputStart = -1;
|
|
this._currentSize = 0;
|
|
this._inputLen = 0;
|
|
this._inputBuffer = null;
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
if (this._hasSegments) {
|
|
clearSegments();
|
|
}
|
|
char[] cArr = this._currentSegment;
|
|
if (cArr != null) {
|
|
return cArr;
|
|
}
|
|
char[] findBuffer = findBuffer(0);
|
|
this._currentSegment = findBuffer;
|
|
return findBuffer;
|
|
}
|
|
|
|
public void ensureNotShared() {
|
|
if (this._inputStart >= 0) {
|
|
unshare(16);
|
|
}
|
|
}
|
|
|
|
public char[] expandCurrentSegment() {
|
|
char[] cArr = this._currentSegment;
|
|
int length = cArr.length;
|
|
char[] _charArray = _charArray(length == 262144 ? 262145 : Math.min(262144, (length >> 1) + length));
|
|
this._currentSegment = _charArray;
|
|
System.arraycopy(cArr, 0, _charArray, 0, length);
|
|
return this._currentSegment;
|
|
}
|
|
|
|
public char[] finishCurrentSegment() {
|
|
if (this._segments == null) {
|
|
this._segments = new ArrayList<>();
|
|
}
|
|
this._hasSegments = true;
|
|
this._segments.add(this._currentSegment);
|
|
int length = this._currentSegment.length;
|
|
this._segmentSize += length;
|
|
char[] _charArray = _charArray(Math.min(length + (length >> 1), 262144));
|
|
this._currentSize = 0;
|
|
this._currentSegment = _charArray;
|
|
return _charArray;
|
|
}
|
|
|
|
public char[] getCurrentSegment() {
|
|
if (this._inputStart >= 0) {
|
|
unshare(1);
|
|
} else {
|
|
char[] cArr = this._currentSegment;
|
|
if (cArr == null) {
|
|
this._currentSegment = findBuffer(0);
|
|
} else if (this._currentSize >= cArr.length) {
|
|
expand(1);
|
|
}
|
|
}
|
|
return this._currentSegment;
|
|
}
|
|
|
|
public int getCurrentSegmentSize() {
|
|
return this._currentSize;
|
|
}
|
|
|
|
public char[] getTextBuffer() {
|
|
if (this._inputStart >= 0) {
|
|
return this._inputBuffer;
|
|
}
|
|
char[] cArr = this._resultArray;
|
|
if (cArr != null) {
|
|
return cArr;
|
|
}
|
|
String str = this._resultString;
|
|
if (str == null) {
|
|
return !this._hasSegments ? this._currentSegment : contentsAsArray();
|
|
}
|
|
char[] charArray = str.toCharArray();
|
|
this._resultArray = charArray;
|
|
return charArray;
|
|
}
|
|
|
|
public int getTextOffset() {
|
|
int i = this._inputStart;
|
|
if (i >= 0) {
|
|
return i;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public boolean hasTextAsCharacters() {
|
|
return this._inputStart >= 0 || this._resultArray != null || this._resultString == null;
|
|
}
|
|
|
|
public void releaseBuffers() {
|
|
if (this._allocator == null) {
|
|
resetWithEmpty();
|
|
} else if (this._currentSegment != null) {
|
|
resetWithEmpty();
|
|
char[] cArr = this._currentSegment;
|
|
this._currentSegment = null;
|
|
this._allocator.releaseCharBuffer(BufferRecycler.CharBufferType.TEXT_BUFFER, cArr);
|
|
}
|
|
}
|
|
|
|
public void resetWithCopy(char[] cArr, int i, int i2) {
|
|
this._inputBuffer = null;
|
|
this._inputStart = -1;
|
|
this._inputLen = 0;
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
if (this._hasSegments) {
|
|
clearSegments();
|
|
} else if (this._currentSegment == null) {
|
|
this._currentSegment = findBuffer(i2);
|
|
}
|
|
this._segmentSize = 0;
|
|
this._currentSize = 0;
|
|
append(cArr, i, i2);
|
|
}
|
|
|
|
public void resetWithEmpty() {
|
|
this._inputStart = -1;
|
|
this._currentSize = 0;
|
|
this._inputLen = 0;
|
|
this._inputBuffer = null;
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
if (this._hasSegments) {
|
|
clearSegments();
|
|
}
|
|
}
|
|
|
|
public void resetWithShared(char[] cArr, int i, int i2) {
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
this._inputBuffer = cArr;
|
|
this._inputStart = i;
|
|
this._inputLen = i2;
|
|
if (this._hasSegments) {
|
|
clearSegments();
|
|
}
|
|
}
|
|
|
|
public void resetWithString(String str) {
|
|
this._inputBuffer = null;
|
|
this._inputStart = -1;
|
|
this._inputLen = 0;
|
|
this._resultString = str;
|
|
this._resultArray = null;
|
|
if (this._hasSegments) {
|
|
clearSegments();
|
|
}
|
|
this._currentSize = 0;
|
|
}
|
|
|
|
public void setCurrentLength(int i) {
|
|
this._currentSize = i;
|
|
}
|
|
|
|
public int size() {
|
|
if (this._inputStart >= 0) {
|
|
return this._inputLen;
|
|
}
|
|
char[] cArr = this._resultArray;
|
|
if (cArr != null) {
|
|
return cArr.length;
|
|
}
|
|
String str = this._resultString;
|
|
return str != null ? str.length() : this._segmentSize + this._currentSize;
|
|
}
|
|
|
|
public String toString() {
|
|
return contentsAsString();
|
|
}
|
|
|
|
public void append(char[] cArr, int i, int i2) {
|
|
if (this._inputStart >= 0) {
|
|
unshare(i2);
|
|
}
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
char[] cArr2 = this._currentSegment;
|
|
int length = cArr2.length;
|
|
int i3 = this._currentSize;
|
|
int i4 = length - i3;
|
|
if (i4 >= i2) {
|
|
System.arraycopy(cArr, i, cArr2, i3, i2);
|
|
this._currentSize += i2;
|
|
return;
|
|
}
|
|
if (i4 > 0) {
|
|
System.arraycopy(cArr, i, cArr2, i3, i4);
|
|
i += i4;
|
|
i2 -= i4;
|
|
}
|
|
do {
|
|
expand(i2);
|
|
int min = Math.min(this._currentSegment.length, i2);
|
|
System.arraycopy(cArr, i, this._currentSegment, 0, min);
|
|
this._currentSize += min;
|
|
i += min;
|
|
i2 -= min;
|
|
} while (i2 > 0);
|
|
}
|
|
|
|
public void append(char c) {
|
|
if (this._inputStart >= 0) {
|
|
unshare(16);
|
|
}
|
|
this._resultString = null;
|
|
this._resultArray = null;
|
|
char[] cArr = this._currentSegment;
|
|
if (this._currentSize >= cArr.length) {
|
|
expand(1);
|
|
cArr = this._currentSegment;
|
|
}
|
|
int i = this._currentSize;
|
|
this._currentSize = i + 1;
|
|
cArr[i] = c;
|
|
}
|
|
}
|