what-the-bank/sources/io/grpc/Status.java

362 lines
13 KiB
Java

package io.grpc;
import com.google.common.base.Charsets;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import io.grpc.Metadata;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.TreeMap;
import net.sf.scuba.smartcards.ISO7816;
import org.jmrtd.lds.CVCAFile;
/* loaded from: classes6.dex */
public final class Status {
static final boolean $assertionsDisabled = false;
static final Metadata.Key<Status> CODE_KEY;
static final Metadata.Key<String> MESSAGE_KEY;
private static final Metadata.TrustedAsciiMarshaller<String> STATUS_MESSAGE_MARSHALLER;
private final Throwable cause;
private final Code code;
private final String description;
private static final String TEST_EQUALS_FAILURE_PROPERTY = "io.grpc.Status.failOnEqualsForTest";
private static final boolean FAIL_ON_EQUALS_FOR_TEST = Boolean.parseBoolean(System.getProperty(TEST_EQUALS_FAILURE_PROPERTY, "false"));
private static final List<Status> STATUS_LIST = buildStatusList();
public static final Status OK = Code.OK.toStatus();
public static final Status CANCELLED = Code.CANCELLED.toStatus();
public static final Status UNKNOWN = Code.UNKNOWN.toStatus();
public static final Status INVALID_ARGUMENT = Code.INVALID_ARGUMENT.toStatus();
public static final Status DEADLINE_EXCEEDED = Code.DEADLINE_EXCEEDED.toStatus();
public static final Status NOT_FOUND = Code.NOT_FOUND.toStatus();
public static final Status ALREADY_EXISTS = Code.ALREADY_EXISTS.toStatus();
public static final Status PERMISSION_DENIED = Code.PERMISSION_DENIED.toStatus();
public static final Status UNAUTHENTICATED = Code.UNAUTHENTICATED.toStatus();
public static final Status RESOURCE_EXHAUSTED = Code.RESOURCE_EXHAUSTED.toStatus();
public static final Status FAILED_PRECONDITION = Code.FAILED_PRECONDITION.toStatus();
public static final Status ABORTED = Code.ABORTED.toStatus();
public static final Status OUT_OF_RANGE = Code.OUT_OF_RANGE.toStatus();
public static final Status UNIMPLEMENTED = Code.UNIMPLEMENTED.toStatus();
public static final Status INTERNAL = Code.INTERNAL.toStatus();
public static final Status UNAVAILABLE = Code.UNAVAILABLE.toStatus();
public static final Status DATA_LOSS = Code.DATA_LOSS.toStatus();
/* loaded from: classes6.dex */
public enum Code {
OK(0),
CANCELLED(1),
UNKNOWN(2),
INVALID_ARGUMENT(3),
DEADLINE_EXCEEDED(4),
NOT_FOUND(5),
ALREADY_EXISTS(6),
PERMISSION_DENIED(7),
RESOURCE_EXHAUSTED(8),
FAILED_PRECONDITION(9),
ABORTED(10),
OUT_OF_RANGE(11),
UNIMPLEMENTED(12),
INTERNAL(13),
UNAVAILABLE(14),
DATA_LOSS(15),
UNAUTHENTICATED(16);
private final int value;
private final byte[] valueAscii;
Code(int i) {
this.value = i;
this.valueAscii = Integer.toString(i).getBytes(Charsets.US_ASCII);
}
public final Status toStatus() {
return (Status) Status.STATUS_LIST.get(this.value);
}
public final int value() {
return this.value;
}
/* JADX INFO: Access modifiers changed from: private */
public byte[] valueAscii() {
return this.valueAscii;
}
}
static {
CODE_KEY = Metadata.Key.of("grpc-status", false, (Metadata.TrustedAsciiMarshaller) new StatusCodeMarshaller());
StatusMessageMarshaller statusMessageMarshaller = new StatusMessageMarshaller();
STATUS_MESSAGE_MARSHALLER = statusMessageMarshaller;
MESSAGE_KEY = Metadata.Key.of("grpc-message", false, (Metadata.TrustedAsciiMarshaller) statusMessageMarshaller);
}
private static List<Status> buildStatusList() {
TreeMap treeMap = new TreeMap();
for (Code code : Code.values()) {
Status status = (Status) treeMap.put(Integer.valueOf(code.value()), new Status(code));
if (status != null) {
StringBuilder sb = new StringBuilder("Code value duplication between ");
sb.append(status.getCode().name());
sb.append(" & ");
sb.append(code.name());
throw new IllegalStateException(sb.toString());
}
}
return Collections.unmodifiableList(new ArrayList(treeMap.values()));
}
public static Status fromCodeValue(int i) {
if (i >= 0) {
List<Status> list = STATUS_LIST;
if (i <= list.size()) {
return list.get(i);
}
}
return UNKNOWN.withDescription("Unknown code ".concat(String.valueOf(i)));
}
/* JADX INFO: Access modifiers changed from: private */
public static Status fromCodeValue(byte[] bArr) {
return (bArr.length == 1 && bArr[0] == 48) ? OK : fromCodeValueSlow(bArr);
}
private static Status fromCodeValueSlow(byte[] bArr) {
int i;
byte b;
int length = bArr.length;
char c = 1;
if (length != 1) {
i = (length == 2 && (b = bArr[0]) >= 48 && b <= 57) ? (b - ISO7816.INS_DECREASE) * 10 : 0;
return UNKNOWN.withDescription("Unknown code ".concat(new String(bArr, Charsets.US_ASCII)));
}
c = 0;
byte b2 = bArr[c];
if (b2 >= 48 && b2 <= 57) {
int i2 = i + (b2 - ISO7816.INS_DECREASE);
List<Status> list = STATUS_LIST;
if (i2 < list.size()) {
return list.get(i2);
}
}
return UNKNOWN.withDescription("Unknown code ".concat(new String(bArr, Charsets.US_ASCII)));
}
public static Status fromCode(Code code) {
return code.toStatus();
}
public static Status fromThrowable(Throwable th) {
for (Throwable th2 = (Throwable) Preconditions.checkNotNull(th, "t"); th2 != null; th2 = th2.getCause()) {
if (th2 instanceof StatusException) {
return ((StatusException) th2).getStatus();
}
if (th2 instanceof StatusRuntimeException) {
return ((StatusRuntimeException) th2).getStatus();
}
}
return UNKNOWN.withCause(th);
}
public static Metadata trailersFromThrowable(Throwable th) {
for (Throwable th2 = (Throwable) Preconditions.checkNotNull(th, "t"); th2 != null; th2 = th2.getCause()) {
if (th2 instanceof StatusException) {
return ((StatusException) th2).getTrailers();
}
if (th2 instanceof StatusRuntimeException) {
return ((StatusRuntimeException) th2).getTrailers();
}
}
return null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String formatThrowableMessage(Status status) {
if (status.description == null) {
return status.code.toString();
}
StringBuilder sb = new StringBuilder();
sb.append(status.code);
sb.append(": ");
sb.append(status.description);
return sb.toString();
}
private Status(Code code) {
this(code, null, null);
}
private Status(Code code, String str, Throwable th) {
this.code = (Code) Preconditions.checkNotNull(code, "code");
this.description = str;
this.cause = th;
}
public final Status withCause(Throwable th) {
return Objects.equal(this.cause, th) ? this : new Status(this.code, this.description, th);
}
public final Status withDescription(String str) {
return Objects.equal(this.description, str) ? this : new Status(this.code, str, this.cause);
}
public final Status augmentDescription(String str) {
if (str == null) {
return this;
}
if (this.description == null) {
return new Status(this.code, str, this.cause);
}
Code code = this.code;
StringBuilder sb = new StringBuilder();
sb.append(this.description);
sb.append("\n");
sb.append(str);
return new Status(code, sb.toString(), this.cause);
}
public final boolean isOk() {
return Code.OK == this.code;
}
public final StatusRuntimeException asRuntimeException() {
return new StatusRuntimeException(this);
}
public final StatusRuntimeException asRuntimeException(Metadata metadata) {
return new StatusRuntimeException(this, metadata);
}
public final StatusException asException() {
return new StatusException(this);
}
public final StatusException asException(Metadata metadata) {
return new StatusException(this, metadata);
}
public final String toString() {
MoreObjects.ToStringHelper add = MoreObjects.toStringHelper(this).add("code", this.code.name()).add("description", this.description);
Throwable th = this.cause;
Object obj = th;
if (th != null) {
obj = Throwables.getStackTraceAsString(th);
}
return add.add("cause", obj).toString();
}
/* loaded from: classes6.dex */
static final class StatusCodeMarshaller implements Metadata.TrustedAsciiMarshaller<Status> {
private StatusCodeMarshaller() {
}
@Override // io.grpc.Metadata.TrustedAsciiMarshaller
public final byte[] toAsciiString(Status status) {
return status.getCode().valueAscii();
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // io.grpc.Metadata.TrustedAsciiMarshaller
public final Status parseAsciiString(byte[] bArr) {
return Status.fromCodeValue(bArr);
}
}
/* loaded from: classes6.dex */
static final class StatusMessageMarshaller implements Metadata.TrustedAsciiMarshaller<String> {
private static final byte[] HEX = {ISO7816.INS_DECREASE, 49, ISO7816.INS_INCREASE, 51, ISO7816.INS_DECREASE_STAMPED, 53, 54, 55, 56, 57, 65, CVCAFile.CAR_TAG, 67, ISO7816.INS_REHABILITATE_CHV, 69, 70};
private static boolean isEscapingChar(byte b) {
return b < 32 || b >= 126 || b == 37;
}
private StatusMessageMarshaller() {
}
@Override // io.grpc.Metadata.TrustedAsciiMarshaller
public final byte[] toAsciiString(String str) {
byte[] bytes = str.getBytes(Charsets.UTF_8);
for (int i = 0; i < bytes.length; i++) {
if (isEscapingChar(bytes[i])) {
return toAsciiStringSlow(bytes, i);
}
}
return bytes;
}
private static byte[] toAsciiStringSlow(byte[] bArr, int i) {
byte[] bArr2 = new byte[((bArr.length - i) * 3) + i];
if (i != 0) {
System.arraycopy(bArr, 0, bArr2, 0, i);
}
int i2 = i;
while (i < bArr.length) {
byte b = bArr[i];
if (isEscapingChar(b)) {
bArr2[i2] = 37;
byte[] bArr3 = HEX;
bArr2[i2 + 1] = bArr3[(b >> 4) & 15];
bArr2[i2 + 2] = bArr3[b & 15];
i2 += 3;
} else {
bArr2[i2] = b;
i2++;
}
i++;
}
return Arrays.copyOf(bArr2, i2);
}
@Override // io.grpc.Metadata.TrustedAsciiMarshaller
public final String parseAsciiString(byte[] bArr) {
for (int i = 0; i < bArr.length; i++) {
byte b = bArr[i];
if (b < 32 || b >= 126 || (b == 37 && i + 2 < bArr.length)) {
return parseAsciiStringSlow(bArr);
}
}
return new String(bArr, 0);
}
private static String parseAsciiStringSlow(byte[] bArr) {
ByteBuffer allocate = ByteBuffer.allocate(bArr.length);
int i = 0;
while (i < bArr.length) {
if (bArr[i] == 37 && i + 2 < bArr.length) {
try {
allocate.put((byte) Integer.parseInt(new String(bArr, i + 1, 2, Charsets.US_ASCII), 16));
i += 3;
} catch (NumberFormatException unused) {
}
}
allocate.put(bArr[i]);
i++;
}
return new String(allocate.array(), 0, allocate.position(), Charsets.UTF_8);
}
}
public final boolean equals(Object obj) {
return super.equals(obj);
}
public final int hashCode() {
return super.hashCode();
}
public final String getDescription() {
return this.description;
}
public final Code getCode() {
return this.code;
}
public final Throwable getCause() {
return this.cause;
}
}