2021-06-27 20:44:35 +00:00
|
|
|
package com.discord.utilities.rest;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
2021-07-19 19:45:22 +00:00
|
|
|
import c.d.b.a.a;
|
2021-06-27 20:44:35 +00:00
|
|
|
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-07-19 19:45:22 +00:00
|
|
|
MediaType.a aVar = MediaType.f2871c;
|
2021-06-27 20:44:35 +00:00
|
|
|
return MediaType.a.b(AttachmentUtilsKt.getMimeType(this.attachment, this.contentResolver));
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:45:22 +00:00
|
|
|
public String toString() {
|
|
|
|
StringBuilder K = a.K("AttachmentRequestBody(attachment=");
|
|
|
|
K.append(this.attachment);
|
|
|
|
K.append(", size=");
|
|
|
|
K.append(this.size);
|
|
|
|
K.append(')');
|
|
|
|
return K.toString();
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|