96 lines
3.0 KiB
Java
96 lines
3.0 KiB
Java
package com.baidu.uaq.agent.android.util;
|
|
|
|
import com.baidu.uaq.agent.android.logging.a;
|
|
import com.ubt.jimu.unity.bluetooth.UnityActivity;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.Closeable;
|
|
import java.io.IOException;
|
|
import java.util.zip.Deflater;
|
|
import java.util.zip.GZIPOutputStream;
|
|
|
|
/* compiled from: CompressUtil.java */
|
|
/* loaded from: classes.dex */
|
|
public class b {
|
|
private static final a a = com.baidu.uaq.agent.android.logging.b.a();
|
|
|
|
public static byte[] a(String str, String str2) {
|
|
ByteArrayOutputStream byteArrayOutputStream;
|
|
if (str == null || str.length() == 0) {
|
|
return null;
|
|
}
|
|
try {
|
|
byteArrayOutputStream = new ByteArrayOutputStream();
|
|
} catch (IOException e) {
|
|
e = e;
|
|
byteArrayOutputStream = null;
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
byteArrayOutputStream = null;
|
|
a(byteArrayOutputStream);
|
|
throw th;
|
|
}
|
|
try {
|
|
try {
|
|
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
|
|
gZIPOutputStream.write(str.getBytes(str2));
|
|
gZIPOutputStream.close();
|
|
byte[] byteArray = byteArrayOutputStream.toByteArray();
|
|
a(byteArrayOutputStream);
|
|
return byteArray;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
a(byteArrayOutputStream);
|
|
throw th;
|
|
}
|
|
} catch (IOException e2) {
|
|
e = e2;
|
|
a.a("gzip compress exception: ", e);
|
|
a(byteArrayOutputStream);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static byte[] a(String str) {
|
|
Throwable th;
|
|
ByteArrayOutputStream byteArrayOutputStream;
|
|
Deflater deflater;
|
|
try {
|
|
deflater = new Deflater();
|
|
deflater.setInput(str.getBytes());
|
|
deflater.finish();
|
|
byteArrayOutputStream = new ByteArrayOutputStream();
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
byteArrayOutputStream = null;
|
|
}
|
|
try {
|
|
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
|
|
while (!deflater.finished()) {
|
|
int deflate = deflater.deflate(bArr);
|
|
if (deflate <= 0) {
|
|
a.a("HTTP request contains an incomplete payload");
|
|
}
|
|
byteArrayOutputStream.write(bArr, 0, deflate);
|
|
}
|
|
deflater.end();
|
|
byte[] byteArray = byteArrayOutputStream.toByteArray();
|
|
a(byteArrayOutputStream);
|
|
return byteArray;
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
a(byteArrayOutputStream);
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public static void a(Closeable closeable) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (IOException unused) {
|
|
a.a("Failed to close io.");
|
|
}
|
|
}
|
|
}
|
|
}
|