package o; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.Iterator; import java.util.List; /* renamed from: o.gkZ, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public abstract class AbstractC15213gkZ { private String c; final Charset e; private static final C15260glo b = a(C15212gkX.a, ": "); private static final C15260glo d = a(C15212gkX.a, "\r\n"); private static final C15260glo a = a(C15212gkX.a, "--"); protected abstract void b(gkV gkv, OutputStream outputStream) throws IOException; public abstract List e(); private static C15260glo a(Charset charset, String str) { ByteBuffer encode = charset.encode(CharBuffer.wrap(str)); C15260glo c15260glo = new C15260glo(encode.remaining()); c15260glo.c(encode.array(), encode.position(), encode.remaining()); return c15260glo; } public AbstractC15213gkZ(Charset charset, String str) { C15264gls.c(str, "Multipart boundary"); this.e = charset == null ? C15212gkX.a : charset; this.c = str; } public final void b(OutputStream outputStream, boolean z) throws IOException { C15260glo a2 = a(this.e, this.c); for (gkV gkv : e()) { C15260glo c15260glo = a; outputStream.write(c15260glo.b, 0, c15260glo.a); outputStream.write(a2.b, 0, a2.a); C15260glo c15260glo2 = d; outputStream.write(c15260glo2.b, 0, c15260glo2.a); b(gkv, outputStream); outputStream.write(c15260glo2.b, 0, c15260glo2.a); if (z) { gkv.c.c(outputStream); } outputStream.write(c15260glo2.b, 0, c15260glo2.a); } C15260glo c15260glo3 = a; outputStream.write(c15260glo3.b, 0, c15260glo3.a); outputStream.write(a2.b, 0, a2.a); outputStream.write(c15260glo3.b, 0, c15260glo3.a); C15260glo c15260glo4 = d; outputStream.write(c15260glo4.b, 0, c15260glo4.a); } public final long a() { Iterator it = e().iterator(); long j = 0; while (it.hasNext()) { long d2 = it.next().c.d(); if (d2 < 0) { return -1L; } j += d2; } try { b((OutputStream) new ByteArrayOutputStream(), false); return j + r0.toByteArray().length; } catch (IOException unused) { return -1L; } } /* JADX INFO: Access modifiers changed from: protected */ public static void d(C15247glb c15247glb, OutputStream outputStream) throws IOException { C15260glo a2 = a(C15212gkX.a, c15247glb.d); outputStream.write(a2.b, 0, a2.a); C15260glo c15260glo = b; outputStream.write(c15260glo.b, 0, c15260glo.a); C15260glo a3 = a(C15212gkX.a, c15247glb.c); outputStream.write(a3.b, 0, a3.a); C15260glo c15260glo2 = d; outputStream.write(c15260glo2.b, 0, c15260glo2.a); } /* JADX INFO: Access modifiers changed from: protected */ public static void e(C15247glb c15247glb, Charset charset, OutputStream outputStream) throws IOException { C15260glo a2 = a(charset, c15247glb.d); outputStream.write(a2.b, 0, a2.a); C15260glo c15260glo = b; outputStream.write(c15260glo.b, 0, c15260glo.a); C15260glo a3 = a(charset, c15247glb.c); outputStream.write(a3.b, 0, a3.a); C15260glo c15260glo2 = d; outputStream.write(c15260glo2.b, 0, c15260glo2.a); } }