2021-08-09 22:50:52 +00:00
|
|
|
package com.discord.utilities.rest;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import c.d.b.a.a;
|
|
|
|
import com.discord.app.AppLog;
|
|
|
|
import com.discord.utilities.attachments.AttachmentUtilsKt;
|
|
|
|
import com.lytefast.flexinput.model.Attachment;
|
|
|
|
import d0.y.b;
|
|
|
|
import d0.z.d.m;
|
|
|
|
import g0.n;
|
|
|
|
import g0.y;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
import okio.BufferedSink;
|
|
|
|
/* compiled from: AttachmentRequestBody.kt */
|
|
|
|
public final class AttachmentRequestBody extends RequestBody {
|
|
|
|
private final Attachment<?> attachment;
|
|
|
|
private final ContentResolver contentResolver;
|
|
|
|
private final long size;
|
|
|
|
|
|
|
|
public AttachmentRequestBody(ContentResolver contentResolver, Attachment<?> attachment) {
|
|
|
|
m.checkNotNullParameter(contentResolver, "contentResolver");
|
|
|
|
m.checkNotNullParameter(attachment, "attachment");
|
|
|
|
this.contentResolver = contentResolver;
|
|
|
|
this.attachment = attachment;
|
|
|
|
Object data = attachment.getData();
|
|
|
|
File file = (File) (!(data instanceof File) ? null : data);
|
|
|
|
this.size = file != null ? file.length() : SendUtilsKt.computeFileSizeBytes(attachment.getUri(), contentResolver);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // okhttp3.RequestBody
|
|
|
|
public long contentLength() {
|
|
|
|
return this.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // okhttp3.RequestBody
|
|
|
|
public MediaType contentType() {
|
2021-08-19 17:35:23 +00:00
|
|
|
MediaType.a aVar = MediaType.f2908c;
|
2021-08-09 22:50:52 +00:00
|
|
|
return MediaType.a.b(AttachmentUtilsKt.getMimeType(this.attachment, this.contentResolver));
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
2021-08-18 07:29:27 +00:00
|
|
|
StringBuilder L = a.L("AttachmentRequestBody(attachment=");
|
|
|
|
L.append(this.attachment);
|
|
|
|
L.append(", size=");
|
|
|
|
L.append(this.size);
|
|
|
|
L.append(')');
|
|
|
|
return L.toString();
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:13:0x0035, code lost:
|
|
|
|
r2 = move-exception;
|
|
|
|
*/
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:14:0x0036, code lost:
|
|
|
|
d0.y.b.closeFinally(r1, r4);
|
|
|
|
*/
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:15:0x0039, code lost:
|
|
|
|
throw r2;
|
|
|
|
*/
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:19:0x003c, code lost:
|
|
|
|
r1 = move-exception;
|
|
|
|
*/
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:20:0x003d, code lost:
|
|
|
|
d0.y.b.closeFinally(r0, r4);
|
|
|
|
*/
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:21:0x0040, code lost:
|
|
|
|
throw r1;
|
|
|
|
*/
|
|
|
|
@Override // okhttp3.RequestBody
|
|
|
|
public void writeTo(BufferedSink bufferedSink) throws IOException {
|
|
|
|
m.checkNotNullParameter(bufferedSink, "sink");
|
|
|
|
try {
|
|
|
|
InputStream openInputStream = this.contentResolver.openInputStream(this.attachment.getUri());
|
|
|
|
if (openInputStream != null) {
|
|
|
|
m.checkNotNullExpressionValue(openInputStream, "inputStream");
|
|
|
|
m.checkParameterIsNotNull(openInputStream, "$this$source");
|
|
|
|
n nVar = new n(openInputStream, new y());
|
|
|
|
bufferedSink.O(nVar);
|
|
|
|
b.closeFinally(nVar, null);
|
|
|
|
b.closeFinally(openInputStream, null);
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
AppLog.g.i("Could not write to sink", e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|