m.java 源代码
package com.mbridge.msdk.foundation.same.net;
import android.text.TextUtils;
import com.x8zs.plugin.apache.http.HttpStatus;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class m {
private static final String f17093a = "m";
private static String f17094b = com.mbridge.msdk.foundation.tools.l.b("DkPtYdQTLkfAW+xUhoPwLkPTHkJBDkM/Yr5T");
private static int f17095c = 9377;
private static volatile AtomicInteger f17096d = new AtomicInteger(1);
private ExecutorService f17097e;
private class a implements Runnable {
private String f17099b;
private ByteBuffer f17100c;
private OutputStream f17101d;
private boolean f17102e = false;
private e f17103f;
private Socket f17104g;
a(String str, e eVar) {
this.f17099b = str;
this.f17103f = eVar;
}
@Override
public final void run() {
byte b6;
try {
try {
Socket socket = new Socket(m.f17094b, m.f17095c);
this.f17104g = socket;
socket.setSoTimeout(15000);
this.f17101d = this.f17104g.getOutputStream();
ByteBuffer wrap = ByteBuffer.wrap(new byte[8]);
this.f17100c = wrap;
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
wrap.order(byteOrder);
this.f17100c.put((byte) 1);
if (TextUtils.isEmpty(this.f17099b)) {
this.f17100c.put((byte) 1);
} else {
ByteBuffer byteBuffer = this.f17100c;
if (this.f17102e) {
b6 = 3;
} else {
b6 = 2;
}
byteBuffer.put(b6);
}
this.f17100c.putShort((short) m.f17096d.getAndIncrement());
if (TextUtils.isEmpty(this.f17099b)) {
this.f17100c.putInt(0);
this.f17101d.write(this.f17100c.array());
} else {
this.f17100c.putInt(this.f17099b.getBytes().length);
this.f17101d.write(this.f17100c.array());
this.f17101d.write(this.f17099b.getBytes());
}
this.f17101d.flush();
InputStream inputStream = this.f17104g.getInputStream();
byte[] bArr = new byte[8];
inputStream.read(bArr, 0, 8);
ByteBuffer wrap2 = ByteBuffer.wrap(bArr);
this.f17100c = wrap2;
wrap2.order(byteOrder);
int i6 = this.f17100c.getInt(4);
byte[] bArr2 = new byte[i6];
inputStream.read(bArr2, 0, i6);
if (i6 >= 1 && bArr2[0] == 1) {
e eVar = this.f17103f;
if (eVar != null) {
eVar.a(k.a(null, new com.mbridge.msdk.foundation.same.net.f.c(200, null, null)));
}
} else {
e eVar2 = this.f17103f;
if (eVar2 != null) {
eVar2.a(new com.mbridge.msdk.foundation.same.net.a.a(2, new com.mbridge.msdk.foundation.same.net.f.c(HttpStatus.SC_NOT_FOUND, null, null)));
}
}
this.f17104g.close();
this.f17100c = null;
inputStream.close();
this.f17101d.close();
Socket socket2 = this.f17104g;
if (socket2 != null) {
try {
socket2.close();
} catch (IOException e6) {
e = e6;
e.printStackTrace();
this.f17103f = null;
}
}
} catch (Throwable th) {
Socket socket3 = this.f17104g;
if (socket3 != null) {
try {
socket3.close();
} catch (IOException e7) {
e7.printStackTrace();
}
}
this.f17103f = null;
throw th;
}
} catch (Throwable unused) {
e eVar3 = this.f17103f;
if (eVar3 != null) {
eVar3.a(new com.mbridge.msdk.foundation.same.net.a.a(2, new com.mbridge.msdk.foundation.same.net.f.c(HttpStatus.SC_NOT_FOUND, null, null)));
}
Socket socket4 = this.f17104g;
if (socket4 != null) {
try {
socket4.close();
} catch (IOException e8) {
e = e8;
e.printStackTrace();
this.f17103f = null;
}
}
}
this.f17103f = null;
}
}
public static final class b {
private static m f17105a = new m();
}
public final void a(String str) {
f17094b = str;
}
private m() {
this.f17097e = Executors.newCachedThreadPool();
}
public final void a(int i6) {
f17095c = i6;
}
public static m a() {
return b.f17105a;
}
public final synchronized void a(String str, e eVar) {
this.f17097e.execute(new a(str, eVar));
}
}