package com.airbnb.deeplinkdispatch.base; import com.airbnb.deeplinkdispatch.UrlTreeKt; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import o.C13396fZU; import o.C14856gaP; import o.C14881gav; import o.C14957gcv; import o.gbH; import o.gdP; import o.gdW; import o.gdZ; /* loaded from: classes.dex */ public final class Utils { public static final Utils INSTANCE = new Utils(); private Utils() { } public static final byte[] readMatchIndexFromStrings(String[] strArr) { C14957gcv.e(strArr, ""); int i = 0; if (strArr.length == 0) { return new byte[0]; } if (strArr.length == 1) { String str = strArr[0]; Charset forName = Charset.forName(MatchIndex.MATCH_INDEX_ENCODING); C14957gcv.c(forName, ""); byte[] bytes = str.getBytes(forName); C14957gcv.c(bytes, ""); return bytes; } int length = strArr.length; int i2 = 0; int i3 = 0; while (i2 < length) { String str2 = strArr[i2]; i2++; i3 += str2.length(); } StringBuilder sb = new StringBuilder(i3); int length2 = strArr.length; while (i < length2) { String str3 = strArr[i]; i++; sb.append(str3); } String obj = sb.toString(); C14957gcv.c((Object) obj, ""); Charset forName2 = Charset.forName(MatchIndex.MATCH_INDEX_ENCODING); C14957gcv.c(forName2, ""); byte[] bytes2 = obj.getBytes(forName2); C14957gcv.c(bytes2, ""); return bytes2; } public static final Map toByteArrayMap(Map map) { C14957gcv.e(map, ""); Set> entrySet = map.entrySet(); C14957gcv.e(entrySet, ""); int a = C14856gaP.a(entrySet instanceof Collection ? entrySet.size() : 10); if (a < 16) { a = 16; } LinkedHashMap linkedHashMap = new LinkedHashMap(a); Iterator it = entrySet.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); byte[] bytes = ((String) entry.getKey()).getBytes(gdP.a); C14957gcv.c(bytes, ""); byte[] bytes2 = ((String) entry.getValue()).getBytes(gdP.a); C14957gcv.c(bytes2, ""); C13396fZU c13396fZU = new C13396fZU(bytes, bytes2); linkedHashMap.put(c13396fZU.d, c13396fZU.e); } return linkedHashMap; } private final byte[] getBytes(InputStream inputStream) { C14957gcv.e(inputStream, ""); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(Math.max(8192, inputStream.available())); gbH.e(inputStream, byteArrayOutputStream, 8192); byte[] byteArray = byteArrayOutputStream.toByteArray(); C14957gcv.c(byteArray, ""); return byteArray; } public final boolean validateIfComponentParam(String str) { C14957gcv.e(str, ""); String str2 = str; int e = gdZ.e((CharSequence) str2, UrlTreeKt.componentParamPrefix, 0, false); int e2 = gdZ.e((CharSequence) str2, UrlTreeKt.componentParamSuffix, 0, false); if (e == -1 && e2 == -1) { return false; } if (e >= e2) { StringBuilder sb = new StringBuilder("Invalid URI component: "); sb.append(str); sb.append(". { must come before }."); throw new IllegalArgumentException(sb.toString().toString()); } if (e != -1 && e2 != -1) { return true; } StringBuilder sb2 = new StringBuilder("Invalid URI component: "); sb2.append(str); sb2.append(". If either{ or } is present, then they must both be present and { must occur before }."); throw new IllegalArgumentException(sb2.toString().toString()); } public final boolean validateIfConfigurablePathSegment(String str) { C14957gcv.e(str, ""); String str2 = str; gdW gdw = new gdW("<|>"); C14957gcv.e(str2, ""); if (!gdw.e.matcher(str2).find()) { return false; } if (isConfigurablePathSegment(str)) { return true; } StringBuilder sb = new StringBuilder("Malformed path segment: "); sb.append(str); sb.append("! If it contains < or >, it must start with < and end with >."); throw new IllegalArgumentException(sb.toString().toString()); } public static final boolean isConfigurablePathSegment(String str) { C14957gcv.e(str, ""); return gdZ.e(str, UrlTreeKt.configurablePathSegmentPrefix, false) && gdZ.d(str, UrlTreeKt.configurablePathSegmentSuffix, false); } public static final List toByteArraysList(String[] strArr) { C14957gcv.e(strArr, ""); ArrayList arrayList = new ArrayList(strArr.length); int length = strArr.length; int i = 0; while (i < length) { String str = strArr[i]; i++; byte[] bytes = str.getBytes(gdP.a); C14957gcv.c(bytes, ""); arrayList.add(bytes); } return C14881gav.d((Iterable) arrayList); } }