alexandroid/decompiled/jadx/sources/com/reactnativecommunity/webview/URLUtil.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

83 lines
3.3 KiB
Java

package com.reactnativecommunity.webview;
import android.net.Uri;
import android.webkit.MimeTypeMap;
import androidx.annotation.Nullable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes9.dex */
public final class URLUtil {
private static final Pattern CONTENT_DISPOSITION_PATTERN = Pattern.compile("attachment(?:;\\s*filename\\s*=\\s*(\"?)([^\"]*)\\1)?(?:;\\s*filename\\s*\\*\\s*=\\s*([^']*)'[^']*'([^']*))?\\s*$", 2);
public static final String guessFileName(String str, @Nullable String str2, @Nullable String str3) {
String str4;
String decode;
int lastIndexOf;
int lastIndexOf2;
String str5 = null;
if (str2 != null) {
str4 = parseContentDisposition(str2);
if (str4 != null && (lastIndexOf2 = str4.lastIndexOf(47) + 1) > 0) {
str4 = str4.substring(lastIndexOf2);
}
} else {
str4 = null;
}
if (str4 == null && (decode = Uri.decode(str)) != null) {
int indexOf = decode.indexOf(63);
if (indexOf > 0) {
decode = decode.substring(0, indexOf);
}
if (!decode.endsWith("/") && (lastIndexOf = decode.lastIndexOf(47) + 1) > 0) {
str4 = decode.substring(lastIndexOf);
}
}
if (str4 == null) {
str4 = "downloadfile";
}
int indexOf2 = str4.indexOf(46);
if (indexOf2 < 0) {
if (str3 != null && (str5 = MimeTypeMap.getSingleton().getExtensionFromMimeType(str3)) != null) {
str5 = ".".concat(str5);
}
if (str5 == null) {
str5 = (str3 == null || !str3.toLowerCase(Locale.ROOT).startsWith("text/")) ? ".bin" : str3.equalsIgnoreCase("text/html") ? ".html" : ".txt";
}
} else {
if (str3 != null) {
String mimeTypeFromExtension = MimeTypeMap.getSingleton().getMimeTypeFromExtension(str4.substring(str4.lastIndexOf(46) + 1));
if (mimeTypeFromExtension != null && !mimeTypeFromExtension.equalsIgnoreCase(str3) && (str5 = MimeTypeMap.getSingleton().getExtensionFromMimeType(str3)) != null) {
str5 = ".".concat(str5);
}
}
if (str5 == null) {
str5 = str4.substring(indexOf2);
}
str4 = str4.substring(0, indexOf2);
}
return str4.concat(str5);
}
public static String parseContentDisposition(String str) {
try {
Matcher matcher = CONTENT_DISPOSITION_PATTERN.matcher(str);
if (!matcher.find()) {
return null;
}
if (matcher.group(3) != null && matcher.group(4) != null) {
try {
return URLDecoder.decode(matcher.group(4), matcher.group(3).isEmpty() ? "UTF-8" : matcher.group(3));
} catch (UnsupportedEncodingException unused) {
}
}
return matcher.group(2);
} catch (IllegalStateException unused2) {
return null;
}
}
}