Files
rr3-apk/decompiled/sources/com/google/protobuf/NioByteString.java
Daniel Elliott f9d20bb3fc Add decompiled APK source code (JADX)
- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:52:23 -08:00

236 lines
7.5 KiB
Java

package com.google.protobuf;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.InvalidMarkException;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
/* loaded from: classes3.dex */
public final class NioByteString extends ByteString.LeafByteString {
private final ByteBuffer buffer;
public NioByteString(ByteBuffer byteBuffer) {
Internal.checkNotNull(byteBuffer, "buffer");
this.buffer = byteBuffer.slice().order(ByteOrder.nativeOrder());
}
private Object writeReplace() {
return ByteString.copyFrom(this.buffer.slice());
}
private void readObject(ObjectInputStream objectInputStream) throws IOException {
throw new InvalidObjectException("NioByteString instances are not to be serialized directly");
}
@Override // com.google.protobuf.ByteString
public byte byteAt(int i) {
try {
return this.buffer.get(i);
} catch (ArrayIndexOutOfBoundsException e) {
throw e;
} catch (IndexOutOfBoundsException e2) {
throw new ArrayIndexOutOfBoundsException(e2.getMessage());
}
}
@Override // com.google.protobuf.ByteString
public byte internalByteAt(int i) {
return byteAt(i);
}
@Override // com.google.protobuf.ByteString
public int size() {
return this.buffer.remaining();
}
@Override // com.google.protobuf.ByteString
public ByteString substring(int i, int i2) {
try {
return new NioByteString(slice(i, i2));
} catch (ArrayIndexOutOfBoundsException e) {
throw e;
} catch (IndexOutOfBoundsException e2) {
throw new ArrayIndexOutOfBoundsException(e2.getMessage());
}
}
@Override // com.google.protobuf.ByteString
public void copyToInternal(byte[] bArr, int i, int i2, int i3) {
ByteBuffer slice = this.buffer.slice();
slice.position(i);
slice.get(bArr, i2, i3);
}
@Override // com.google.protobuf.ByteString
public void copyTo(ByteBuffer byteBuffer) {
byteBuffer.put(this.buffer.slice());
}
@Override // com.google.protobuf.ByteString
public void writeTo(OutputStream outputStream) throws IOException {
outputStream.write(toByteArray());
}
@Override // com.google.protobuf.ByteString.LeafByteString
public boolean equalsRange(ByteString byteString, int i, int i2) {
return substring(0, i2).equals(byteString.substring(i, i2 + i));
}
@Override // com.google.protobuf.ByteString
public void writeToInternal(OutputStream outputStream, int i, int i2) throws IOException {
if (this.buffer.hasArray()) {
outputStream.write(this.buffer.array(), this.buffer.arrayOffset() + this.buffer.position() + i, i2);
} else {
ByteBufferWriter.write(slice(i, i2 + i), outputStream);
}
}
@Override // com.google.protobuf.ByteString
public void writeTo(ByteOutput byteOutput) throws IOException {
byteOutput.writeLazy(this.buffer.slice());
}
@Override // com.google.protobuf.ByteString
public ByteBuffer asReadOnlyByteBuffer() {
return this.buffer.asReadOnlyBuffer();
}
@Override // com.google.protobuf.ByteString
public List<ByteBuffer> asReadOnlyByteBufferList() {
return Collections.singletonList(asReadOnlyByteBuffer());
}
@Override // com.google.protobuf.ByteString
public String toStringInternal(Charset charset) {
byte[] byteArray;
int length;
int i;
if (this.buffer.hasArray()) {
byteArray = this.buffer.array();
i = this.buffer.arrayOffset() + this.buffer.position();
length = this.buffer.remaining();
} else {
byteArray = toByteArray();
length = byteArray.length;
i = 0;
}
return new String(byteArray, i, length, charset);
}
@Override // com.google.protobuf.ByteString
public boolean isValidUtf8() {
return Utf8.isValidUtf8(this.buffer);
}
@Override // com.google.protobuf.ByteString
public int partialIsValidUtf8(int i, int i2, int i3) {
return Utf8.partialIsValidUtf8(i, this.buffer, i2, i3 + i2);
}
@Override // com.google.protobuf.ByteString
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ByteString)) {
return false;
}
ByteString byteString = (ByteString) obj;
if (size() != byteString.size()) {
return false;
}
if (size() == 0) {
return true;
}
if (obj instanceof NioByteString) {
return this.buffer.equals(((NioByteString) obj).buffer);
}
if (obj instanceof RopeByteString) {
return obj.equals(this);
}
return this.buffer.equals(byteString.asReadOnlyByteBuffer());
}
@Override // com.google.protobuf.ByteString
public int partialHash(int i, int i2, int i3) {
for (int i4 = i2; i4 < i2 + i3; i4++) {
i = (i * 31) + this.buffer.get(i4);
}
return i;
}
@Override // com.google.protobuf.ByteString
public InputStream newInput() {
return new InputStream() { // from class: com.google.protobuf.NioByteString.1
private final ByteBuffer buf;
@Override // java.io.InputStream
public boolean markSupported() {
return true;
}
{
this.buf = NioByteString.this.buffer.slice();
}
@Override // java.io.InputStream
public void mark(int i) {
}
@Override // java.io.InputStream
public void reset() throws IOException {
try {
} catch (InvalidMarkException e) {
throw new IOException(e);
}
}
@Override // java.io.InputStream
public int available() throws IOException {
return this.buf.remaining();
}
@Override // java.io.InputStream
public int read() throws IOException {
if (this.buf.hasRemaining()) {
return this.buf.get() & 255;
}
return -1;
}
@Override // java.io.InputStream
public int read(byte[] bArr, int i, int i2) throws IOException {
if (!this.buf.hasRemaining()) {
return -1;
}
int min = Math.min(i2, this.buf.remaining());
this.buf.get(bArr, i, min);
return min;
}
};
}
@Override // com.google.protobuf.ByteString
public CodedInputStream newCodedInput() {
return CodedInputStream.newInstance(this.buffer, true);
}
private ByteBuffer slice(int i, int i2) {
if (i < this.buffer.position() || i2 > this.buffer.limit() || i > i2) {
throw new IllegalArgumentException(String.format("Invalid indices [%d, %d]", Integer.valueOf(i), Integer.valueOf(i2)));
}
ByteBuffer slice = this.buffer.slice();
slice.position(i - this.buffer.position());
slice.limit(i2 - this.buffer.position());
return slice;
}
}