X-plore v4.37.09版本的 MD5 值为:1ac588cd7c13e9578c2d4266387e2f4f
以下内容为反编译后的 x.java 源代码,内容仅作参考
package b7;
import F7.C1160d;
import com.lonelycatgames.Xplore.App;
import com.lonelycatgames.Xplore.FileSystem.h;
import com.lonelycatgames.Xplore.compose.omp.bRSET;
import h7.C6709J;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import v7.InterfaceC7625a;
import w7.AbstractC7771k;
import w7.AbstractC7780t;
import w7.AbstractC7781u;
public abstract class x implements Closeable {
public static final a f22054E = new a(null);
public static final int f22055F = 8;
private final int f22056a;
private final boolean f22057b;
private final ServerSocket f22058c;
private final ThreadPoolExecutor f22059d;
private final i f22060e;
public static final class a {
private a() {
}
public a(AbstractC7771k abstractC7771k) {
this();
}
public final void c(String str) {
}
public final void d(InterfaceC7625a interfaceC7625a) {
}
}
public static abstract class b implements Closeable {
private final boolean f22061a;
private final long f22062b = -1;
private final d f22063c;
public long b() {
return this.f22062b;
}
@Override
public void close() {
}
public d d() {
return this.f22063c;
}
public abstract String f();
public boolean h() {
return this.f22061a;
}
public abstract InputStream i();
public void j(OutputStream outputStream, long j9) {
AbstractC7780t.f(outputStream, "os");
InputStream i9 = i();
try {
h.b.g(com.lonelycatgames.Xplore.FileSystem.h.f44583b, i9, outputStream, null, j9, null, 0L, 0, 0L, 240, null);
t7.c.a(i9, null);
} finally {
}
}
}
public static class c extends IOException {
private final int f22064a;
private final String f22065b;
public static final class a extends c {
public a(String str) {
super(400, "Bad Request", str);
AbstractC7780t.f(str, "msg");
}
}
public static final class b extends c {
public b(String str) {
super(416, "Range not satisfiable", str);
AbstractC7780t.f(str, "msg");
}
}
public c(int i9, String str, String str2) {
super(str2);
AbstractC7780t.f(str, "statusMsg");
this.f22064a = i9;
this.f22065b = str;
}
public c(int i9, String str, String str2, int i10, AbstractC7771k abstractC7771k) {
this(i9, str, (i10 & 4) != 0 ? null : str2);
}
public d a() {
return null;
}
public final int b() {
return this.f22064a;
}
@Override
public String toString() {
return this.f22064a + ' ' + this.f22065b;
}
}
public static final class d extends HashMap {
public d(String... strArr) {
AbstractC7780t.f(strArr, "data");
for (int i9 = 0; i9 < strArr.length; i9 += 2) {
put(strArr[i9], strArr[i9 + 1]);
}
}
public boolean a(String str) {
return super.containsKey(str);
}
public boolean b(String str) {
return super.containsValue(str);
}
public String c(String str) {
return (String) super.get(str);
}
@Override
public final boolean containsKey(Object obj) {
if (obj instanceof String) {
return a((String) obj);
}
return false;
}
@Override
public final boolean containsValue(Object obj) {
if (obj instanceof String) {
return b((String) obj);
}
return false;
}
public Set e() {
return super.entrySet();
}
@Override
public final Set entrySet() {
return e();
}
public Set f() {
return super.keySet();
}
@Override
public final Object get(Object obj) {
if (obj instanceof String) {
return c((String) obj);
}
return null;
}
@Override
public final Object getOrDefault(Object obj, Object obj2) {
return !(obj instanceof String) ? obj2 : h((String) obj, (String) obj2);
}
public String h(String str, String str2) {
return (String) super.getOrDefault(str, str2);
}
public int j() {
return super.size();
}
public Collection k() {
return super.values();
}
@Override
public final Set keySet() {
return f();
}
public String m(String str) {
return (String) super.remove(str);
}
public boolean o(String str, String str2) {
return super.remove(str, str2);
}
@Override
public final Object remove(Object obj) {
if (obj instanceof String) {
return m((String) obj);
}
return null;
}
@Override
public final boolean remove(Object obj, Object obj2) {
if ((obj instanceof String) && (obj2 instanceof String)) {
return o((String) obj, (String) obj2);
}
return false;
}
@Override
public final int size() {
return j();
}
@Override
public final Collection values() {
return k();
}
}
public static final class e extends c {
public e() {
super(304, "Not Modified", "");
}
}
public class f implements Runnable {
final x f22066E;
private final Socket f22067a;
private String f22068b;
private final d f22069c;
public String f22070d;
private StringBuilder f22071e;
public static final class a extends AbstractC7781u implements InterfaceC7625a {
final String f22072b;
a(String str) {
super(0);
this.f22072b = str;
}
@Override
public final String c() {
return "Range: " + this.f22072b;
}
}
static final class b extends AbstractC7781u implements InterfaceC7625a {
public static final b f22073b = new b();
b() {
super(0);
}
@Override
public final String c() {
return "HTTP request @" + Thread.currentThread().getName();
}
}
public static final class c extends AbstractC7781u implements InterfaceC7625a {
final String f22074b;
final long f22075c;
c(String str, long j9) {
super(0);
this.f22074b = str;
this.f22075c = j9;
}
@Override
public final String c() {
return "Response: " + this.f22074b + ", size: " + this.f22075c;
}
}
public static final class d extends AbstractC7781u implements InterfaceC7625a {
d() {
super(0);
}
@Override
public final String c() {
return "writing stream " + f.this.f22067a.hashCode();
}
}
public static final class e extends AbstractC7781u implements InterfaceC7625a {
final IOException f22077b;
e(IOException iOException) {
super(0);
this.f22077b = iOException;
}
@Override
public final String c() {
return t6.k.Q(this.f22077b);
}
}
public static final class C0526f extends AbstractC7781u implements InterfaceC7625a {
C0526f() {
super(0);
}
@Override
public final String c() {
return "sendResponse done " + f.this.f22067a.hashCode();
}
}
public static final class g extends b {
private final String f22079d = "text/plain";
final byte[] f22080e;
g(byte[] bArr) {
this.f22080e = bArr;
}
@Override
public String f() {
return this.f22079d;
}
@Override
public ByteArrayInputStream i() {
return new ByteArrayInputStream(this.f22080e);
}
}
public f(x xVar, Socket socket) {
AbstractC7780t.f(socket, "socket");
this.f22066E = xVar;
this.f22067a = socket;
this.f22069c = new d(new String[0]);
this.f22071e = new StringBuilder(200);
}
private final g b() {
int U8;
CharSequence M02;
CharSequence M03;
BufferedInputStream bufferedInputStream = new BufferedInputStream(this.f22067a.getInputStream());
String e9 = e(bufferedInputStream);
if (e9.length() == 0) {
throw new c.a("Syntax error");
}
StringTokenizer stringTokenizer = new StringTokenizer(e9);
if (!stringTokenizer.hasMoreTokens()) {
throw new c.a("Syntax error");
}
String nextToken = stringTokenizer.nextToken();
AbstractC7780t.e(nextToken, "nextToken(...)");
j(nextToken);
if (!stringTokenizer.hasMoreTokens()) {
throw new c.a("Missing URI");
}
String nextToken2 = stringTokenizer.nextToken();
AbstractC7780t.e(nextToken2, "nextToken(...)");
this.f22068b = nextToken2;
while (bufferedInputStream.available() > 0) {
String e10 = e(bufferedInputStream);
if (e10.length() == 0) {
break;
}
U8 = F7.x.U(e10, ':', 0, false, 6, null);
if (U8 >= 0) {
String substring = e10.substring(0, U8);
AbstractC7780t.e(substring, "substring(...)");
M02 = F7.x.M0(substring);
String lowerCase = M02.toString().toLowerCase(Locale.ROOT);
AbstractC7780t.e(lowerCase, "toLowerCase(...)");
String substring2 = e10.substring(U8 + 1);
AbstractC7780t.e(substring2, "substring(...)");
M03 = F7.x.M0(substring2);
this.f22069c.put(lowerCase, M03.toString());
}
}
if (!AbstractC7780t.a(d(), "POST")) {
return null;
}
this.f22067a.setSoTimeout(30000);
return new g(bufferedInputStream, this.f22069c);
}
private final h c() {
boolean D8;
int U8;
int P8;
long parseLong;
String str = (String) this.f22069c.get("range");
if (str == null) {
return null;
}
D8 = F7.w.D(str, "bytes=", false, 2, null);
if (!D8) {
throw new c.b("Invalid range: " + str);
}
x.f22054E.d(new a(str));
U8 = F7.x.U(str, '-', 0, false, 6, null);
if (U8 == -1) {
throw new c.b("Invalid range: " + str);
}
try {
String substring = str.substring(6, U8);
AbstractC7780t.e(substring, "substring(...)");
long parseLong2 = Long.parseLong(substring);
P8 = F7.x.P(str);
if (U8 == P8) {
parseLong = -1;
} else {
String substring2 = str.substring(U8 + 1);
AbstractC7780t.e(substring2, "substring(...)");
parseLong = Long.parseLong(substring2);
}
return new h(parseLong2, parseLong);
} catch (NumberFormatException e9) {
e9.printStackTrace();
String message = e9.getMessage();
if (message == null) {
message = "Invalid number";
}
throw new c.b(message);
}
}
private final String e(InputStream inputStream) {
this.f22071e.setLength(0);
while (true) {
int read = inputStream.read();
if (read == -1) {
break;
}
if (read == 13) {
inputStream.mark(1);
if (inputStream.read() != 10) {
inputStream.reset();
}
} else {
if (read == 10) {
break;
}
this.f22071e.append((char) read);
}
}
String sb = this.f22071e.toString();
AbstractC7780t.e(sb, "toString(...)");
return sb;
}
private final void f(String str, b bVar, d dVar, long j9) {
a aVar = x.f22054E;
aVar.d(new c(str, j9));
try {
OutputStream outputStream = this.f22067a.getOutputStream();
try {
PrintWriter printWriter = new PrintWriter(outputStream);
printWriter.print("HTTP/1.1 " + str + "\r\n");
String f9 = bVar.f();
if (f9 != null) {
printWriter.print("Content-Type: " + f9 + "\r\n");
}
if (dVar != null) {
k(dVar, printWriter);
}
d d9 = bVar.d();
if (d9 != null) {
k(d9, printWriter);
}
printWriter.print("\r\n");
printWriter.flush();
aVar.d(new d());
AbstractC7780t.c(outputStream);
bVar.j(outputStream, j9);
C6709J c6709j = C6709J.f49946a;
t7.c.a(outputStream, null);
} finally {
}
} catch (IOException e9) {
e9.printStackTrace();
x.f22054E.d(new e(e9));
}
x.f22054E.d(new C0526f());
}
static void g(f fVar, String str, b bVar, d dVar, long j9, int i9, Object obj) {
if (obj != null) {
throw new UnsupportedOperationException(bRSET.CpJW);
}
if ((i9 & 8) != 0) {
j9 = -1;
}
fVar.f(str, bVar, dVar, j9);
}
private final void h(String str, String str2, d dVar) {
byte[] bytes = str2.getBytes(C1160d.f4033b);
AbstractC7780t.e(bytes, "getBytes(...)");
g(this, str, new g(bytes), dVar, 0L, 8, null);
}
static void i(f fVar, String str, String str2, d dVar, int i9, Object obj) {
if (obj != null) {
throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: sendStringResponse");
}
if ((i9 & 4) != 0) {
dVar = null;
}
fVar.h(str, str2, dVar);
}
private final void k(d dVar, PrintWriter printWriter) {
Iterator it = dVar.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
printWriter.print(((String) entry.getKey()) + ": " + ((String) entry.getValue()) + "\r\n");
}
}
public final String d() {
String str = this.f22070d;
if (str != null) {
return str;
}
AbstractC7780t.r("method");
return null;
}
public final void j(String str) {
AbstractC7780t.f(str, "<set-?>");
this.f22070d = str;
}
@Override
public void run() {
String str;
long j9;
long j10;
a aVar = x.f22054E;
aVar.d(b.f22073b);
String str2 = null;
try {
try {
try {
try {
try {
try {
if (this.f22066E.f22057b && !AbstractC7780t.a(this.f22067a.getInetAddress(), this.f22067a.getLocalAddress())) {
throw new c(403, "Only local connections are allowed", null, 4, null);
}
g b9 = b();
h c9 = c();
x xVar = this.f22066E;
String d9 = d();
String str3 = this.f22068b;
if (str3 == null) {
AbstractC7780t.r("urlEncodedFilePath");
str3 = null;
}
b l9 = xVar.l(d9, str3, c9 != null ? Long.valueOf(c9.b()) : null, this.f22069c, b9);
try {
boolean h9 = l9.h();
long b10 = l9.b();
if (c9 != null) {
if (b10 == -1) {
throw new c.b("Unknown file size");
}
if (c9.b() >= b10) {
throw new c.b("Start offset " + c9.b() + " is greater than file size " + b10);
}
if (c9.a() == -1) {
c9.c(b10 - 1);
}
}
d dVar = new d(new String[0]);
if (h9) {
dVar.put("Accept-Ranges", "bytes");
}
long j11 = 0;
if (c9 == null || !h9) {
if (b10 != -1) {
dVar.put("Content-Length", String.valueOf(b10));
}
str = "200 OK";
j9 = -1;
} else {
if (c9.a() != -1) {
j10 = (c9.a() - c9.b()) + 1;
if (j10 < 0) {
j10 = 0;
}
dVar.put("Content-Length", String.valueOf(j10));
} else {
j10 = -1;
}
StringBuilder sb = new StringBuilder();
sb.append("bytes ");
sb.append(c9.b());
sb.append('-');
sb.append(c9.a() == -1 ? "*" : Long.valueOf(c9.a()));
dVar.put("Content-Range", sb.toString() + '/' + b10);
str = "206 Partial Content";
j9 = j10;
}
if (!AbstractC7780t.a(d(), "HEAD")) {
j11 = j9;
}
f(str, l9, dVar, j11);
aVar.c("Http stream finished");
C6709J c6709j = C6709J.f49946a;
t7.c.a(l9, null);
this.f22067a.close();
} catch (Throwable th) {
try {
throw th;
} catch (Throwable th2) {
t7.c.a(l9, th);
throw th2;
}
}
} catch (IOException e9) {
e9.printStackTrace();
}
} catch (Exception e10) {
i(this, "500 Internal Server Error", "Server internal error: " + e10.getMessage(), null, 4, null);
this.f22067a.close();
}
} catch (FileNotFoundException unused) {
StringBuilder sb2 = new StringBuilder();
sb2.append("File not found: ");
String str4 = this.f22068b;
if (str4 == null) {
AbstractC7780t.r("urlEncodedFilePath");
} else {
str2 = str4;
}
sb2.append(str2);
i(this, "404 Not Found", sb2.toString(), null, 4, null);
this.f22067a.close();
}
} catch (c e11) {
String cVar = e11.toString();
String message = e11.getMessage();
if (message == null) {
message = "Unknown error";
}
h(cVar, message, e11.a());
this.f22067a.close();
}
} catch (e e12) {
h(e12.toString(), t6.k.Q(e12), e12.a());
this.f22067a.close();
}
} catch (Throwable th3) {
try {
this.f22067a.close();
throw th3;
} catch (IOException e13) {
e13.printStackTrace();
throw th3;
}
}
}
}
public static final class g extends InputStream {
private final InputStream f22081a;
private long f22082b;
public g(InputStream inputStream, d dVar) {
AbstractC7780t.f(inputStream, "s");
AbstractC7780t.f(dVar, "hdrs");
this.f22081a = inputStream;
String str = (String) dVar.get("content-length");
if (str == null) {
throw new IOException("chunked POST data not supported");
}
this.f22082b = Long.parseLong(str);
}
@Override
public int available() {
return (int) Math.min(this.f22082b, 2147483647L);
}
@Override
public int read() {
if (this.f22082b == 0) {
return -1;
}
int read = this.f22081a.read();
if (read >= 0) {
this.f22082b--;
}
return read;
}
@Override
public int read(byte[] bArr, int i9, int i10) {
AbstractC7780t.f(bArr, "buffer");
long j9 = this.f22082b;
if (j9 == 0) {
return -1;
}
int read = this.f22081a.read(bArr, i9, (int) Math.min(i10, j9));
if (read > 0) {
this.f22082b -= read;
}
return read;
}
}
public static final class h {
private final long f22083a;
private long f22084b;
public h(long j9, long j10) {
this.f22083a = j9;
this.f22084b = j10;
}
public final long a() {
return this.f22084b;
}
public final long b() {
return this.f22083a;
}
public final void c(long j9) {
this.f22084b = j9;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof h)) {
return false;
}
h hVar = (h) obj;
return this.f22083a == hVar.f22083a && this.f22084b == hVar.f22084b;
}
public int hashCode() {
return (Long.hashCode(this.f22083a) * 31) + Long.hashCode(this.f22084b);
}
public String toString() {
return "Range(startFrom=" + this.f22083a + ", endAt=" + this.f22084b + ')';
}
}
public static final class i extends Thread {
final String f22085a;
final x f22086b;
static final class a extends AbstractC7781u implements InterfaceC7625a {
final IOException f22087b;
a(IOException iOException) {
super(0);
this.f22087b = iOException;
}
@Override
public final String c() {
return "HTTP server crash: " + t6.k.Q(this.f22087b);
}
}
i(String str, x xVar, String str2) {
super(str2);
this.f22085a = str;
this.f22086b = xVar;
start();
}
@Override
public void run() {
x.f22054E.c("Started http server " + this.f22085a);
while (!Thread.interrupted()) {
try {
try {
Socket accept = this.f22086b.f22058c.accept();
x xVar = this.f22086b;
AbstractC7780t.c(accept);
this.f22086b.f22059d.execute(xVar.i(accept));
} catch (IOException e9) {
a aVar = x.f22054E;
aVar.d(new a(e9));
aVar.c("exit http server thread");
return;
}
} finally {
x.f22054E.c("exit http server thread");
}
}
}
}
public x(final String str, int i9, int i10, boolean z8) {
AbstractC7780t.f(str, "serverName");
this.f22056a = i9;
this.f22057b = z8;
this.f22058c = new ServerSocket(i9);
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(i10, i10, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(i10), new ThreadPoolExecutor.CallerRunsPolicy());
threadPoolExecutor.allowCoreThreadTimeOut(true);
final AtomicInteger atomicInteger = new AtomicInteger();
threadPoolExecutor.setThreadFactory(new ThreadFactory() {
@Override
public final Thread newThread(Runnable runnable) {
Thread s9;
s9 = x.s(str, atomicInteger, runnable);
return s9;
}
});
this.f22059d = threadPoolExecutor;
this.f22060e = new i(str, this, "HTTP server [" + str + ']');
}
public x(String str, int i9, int i10, boolean z8, int i11, AbstractC7771k abstractC7771k) {
this(str, i9, (i11 & 4) != 0 ? 2 : i10, (i11 & 8) != 0 ? false : z8);
}
public static final Thread s(String str, AtomicInteger atomicInteger, Runnable runnable) {
AbstractC7780t.f(str, "$serverName");
AbstractC7780t.f(atomicInteger, "$counter");
return new Thread(runnable, str + " #" + atomicInteger.incrementAndGet());
}
@Override
public void close() {
f22054E.c("Closing http server");
try {
this.f22058c.close();
this.f22060e.interrupt();
this.f22060e.join(500L);
} catch (IOException e9) {
App.f43875F0.e("Http server close failed: " + t6.k.Q(e9));
}
this.f22059d.shutdown();
}
protected f i(Socket socket) {
AbstractC7780t.f(socket, "socket");
return new f(this, socket);
}
public final int j() {
return this.f22058c.getLocalPort();
}
public String k() {
return "http://127.0.0.1:" + this.f22058c.getLocalPort();
}
protected abstract b l(String str, String str2, Long l9, d dVar, InputStream inputStream);
}