package z9; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; /* loaded from: classes2.dex */ public class a extends OutputStream { /* renamed from: f, reason: collision with root package name */ private static final byte[] f15905f = new byte[0]; /* renamed from: a, reason: collision with root package name */ private final List f15906a; /* renamed from: b, reason: collision with root package name */ private int f15907b; /* renamed from: c, reason: collision with root package name */ private int f15908c; /* renamed from: d, reason: collision with root package name */ private byte[] f15909d; /* renamed from: e, reason: collision with root package name */ private int f15910e; public a() { this(1024); } private void c(int i10) { if (this.f15907b < this.f15906a.size() - 1) { this.f15908c += this.f15909d.length; int i11 = this.f15907b + 1; this.f15907b = i11; this.f15909d = (byte[]) this.f15906a.get(i11); return; } byte[] bArr = this.f15909d; if (bArr == null) { this.f15908c = 0; } else { i10 = Math.max(bArr.length << 1, i10 - this.f15908c); this.f15908c += this.f15909d.length; } this.f15907b++; byte[] bArr2 = new byte[i10]; this.f15909d = bArr2; this.f15906a.add(bArr2); } @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable public void close() { } public String toString() { return new String(z()); } @Override // java.io.OutputStream public void write(byte[] bArr, int i10, int i11) { int i12; if (i10 < 0 || i10 > bArr.length || i11 < 0 || (i12 = i10 + i11) > bArr.length || i12 < 0) { throw new IndexOutOfBoundsException(); } if (i11 == 0) { return; } synchronized (this) { int i13 = this.f15910e; int i14 = i13 + i11; int i15 = i13 - this.f15908c; while (i11 > 0) { int min = Math.min(i11, this.f15909d.length - i15); System.arraycopy(bArr, i12 - i11, this.f15909d, i15, min); i11 -= min; if (i11 > 0) { c(i14); i15 = 0; } } this.f15910e = i14; } } public synchronized byte[] z() { int i10 = this.f15910e; if (i10 == 0) { return f15905f; } byte[] bArr = new byte[i10]; int i11 = 0; for (byte[] bArr2 : this.f15906a) { int min = Math.min(bArr2.length, i10); System.arraycopy(bArr2, 0, bArr, i11, min); i11 += min; i10 -= min; if (i10 == 0) { break; } } return bArr; } public a(int i10) { this.f15906a = new ArrayList(); if (i10 >= 0) { synchronized (this) { c(i10); } } else { throw new IllegalArgumentException("Negative initial size: " + i10); } } @Override // java.io.OutputStream public synchronized void write(int i10) { int i11 = this.f15910e; int i12 = i11 - this.f15908c; if (i12 == this.f15909d.length) { c(i11 + 1); i12 = 0; } this.f15909d[i12] = (byte) i10; this.f15910e++; } }