mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-15 02:17:18 +01:00
73 lines
2.3 KiB
Java
73 lines
2.3 KiB
Java
package com.amazonaws.util;
|
|
|
|
import com.amazon.alexa.ra.core.data.model.Constants;
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.InputStream;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.Arrays;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes6.dex */
|
|
public class BinaryUtils {
|
|
private static final int FF_LOCATION = 6;
|
|
private static final int HEX_LENGTH_8 = 8;
|
|
private static final int HEX_PARSE_16 = 16;
|
|
|
|
public static byte[] copyAllBytesFrom(ByteBuffer byteBuffer) {
|
|
if (byteBuffer == null) {
|
|
return null;
|
|
}
|
|
if (byteBuffer.hasArray()) {
|
|
return Arrays.copyOfRange(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.limit() + byteBuffer.arrayOffset());
|
|
}
|
|
ByteBuffer asReadOnlyBuffer = byteBuffer.asReadOnlyBuffer();
|
|
asReadOnlyBuffer.rewind();
|
|
byte[] bArr = new byte[asReadOnlyBuffer.remaining()];
|
|
asReadOnlyBuffer.get(bArr);
|
|
return bArr;
|
|
}
|
|
|
|
public static byte[] fromBase64(String str) {
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
return Base64.decode(str);
|
|
}
|
|
|
|
public static byte[] fromHex(String str) {
|
|
byte[] bArr = new byte[(str.length() + 1) / 2];
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (i < str.length()) {
|
|
int i3 = i + 2;
|
|
bArr[i2] = (byte) Integer.parseInt(str.substring(i, i3), 16);
|
|
i = i3;
|
|
i2++;
|
|
}
|
|
return bArr;
|
|
}
|
|
|
|
public static String toBase64(byte[] bArr) {
|
|
return Base64.encodeAsString(bArr);
|
|
}
|
|
|
|
public static String toHex(byte[] bArr) {
|
|
StringBuilder sb = new StringBuilder(bArr.length * 2);
|
|
for (byte b : bArr) {
|
|
String hexString = Integer.toHexString(b);
|
|
if (hexString.length() == 1) {
|
|
sb.append(Constants.FEEDBACK_TYPE_DISLIKE);
|
|
} else if (hexString.length() == 8) {
|
|
hexString = hexString.substring(6);
|
|
}
|
|
sb.append(hexString);
|
|
}
|
|
return StringUtils.lowerCase(sb.toString());
|
|
}
|
|
|
|
public static InputStream toStream(ByteBuffer byteBuffer) {
|
|
byte[] bArr = new byte[byteBuffer.remaining()];
|
|
byteBuffer.get(bArr);
|
|
return new ByteArrayInputStream(bArr);
|
|
}
|
|
}
|