add - PushAgent XBiubiu

This commit is contained in:
yangqiang3504
2022-09-01 15:26:19 +08:00
parent 3761c49f38
commit c768b3b9e2
6 changed files with 263 additions and 50 deletions
@@ -257,4 +257,34 @@ public class Misc {
}
return result;
}
public static ArrayList<String> subContent(String content, String startFlag, String endFlag) {
ArrayList<String> result = new ArrayList<>();
if (startFlag.isEmpty() && endFlag.isEmpty()) {
result.add(content);
return result;
}
try {
Pattern pattern = Pattern.compile(escapeExprSpecialWord(startFlag) + "(.*?)" + escapeExprSpecialWord(endFlag));
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
result.add(matcher.group(1));
}
} catch (Throwable th) {
th.printStackTrace();
}
return result;
}
public static String escapeExprSpecialWord(String regexStr) {
if (!regexStr.isEmpty()) {
String[] fbsArr = {"\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|"};
for (String key : fbsArr) {
if (regexStr.contains(key)) {
regexStr = regexStr.replace(key, "\\" + key);
}
}
}
return regexStr;
}
}
@@ -3,11 +3,16 @@ package com.github.catvod.utils.okhttp;
import com.github.catvod.crawler.SpiderDebug;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Response;
@@ -16,7 +21,7 @@ public class OkHttpUtil {
public static final String METHOD_GET = "GET";
public static final String METHOD_POST = "POST";
public static final int DEFAULT_TIMEOUT = 20;
private static final int DEFAULT_TIMEOUT = 15;
private static final Object lockO = new Object();
@@ -27,10 +32,24 @@ public class OkHttpUtil {
*/
private static OkHttpClient noRedirectClient = null;
public static HashMap<String, List<Cookie>> cookieStore = new HashMap<>();
public static OkHttpClient defaultClient() {
synchronized (lockO) {
if (defaultClient == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(new CookieJar() {
@Override
public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
cookieStore.put(httpUrl.host(), list);
}
@Override
public List<Cookie> loadForRequest(HttpUrl httpUrl) {
List<Cookie> cookies = cookieStore.get(httpUrl.host());
return cookies != null ? cookies : new ArrayList<>();
}
})
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
@@ -164,7 +183,7 @@ public class OkHttpUtil {
public static void cancel(Object tag) {
cancel(defaultClient(), tag);
}
public static void cancelAll() {
cancelAll(defaultClient());
}
@@ -197,4 +216,4 @@ public class OkHttpUtil {
return headers.get("Location").get(0);
return null;
}
}
}