package com.google.android.gms.internal.firebase_ml; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.text.NumberFormat; import java.util.logging.Level; import java.util.logging.Logger; /* loaded from: classes2.dex */ public final class zzhp extends ByteArrayOutputStream { private boolean closed; private final Logger logger; private final int zzaaa; private final Level zzaab; private int zzzz; public zzhp(Logger logger, Level level, int i) { this.logger = (Logger) zzks.checkNotNull(logger); this.zzaab = (Level) zzks.checkNotNull(level); zzks.checkArgument(i >= 0); this.zzaaa = i; } @Override // java.io.ByteArrayOutputStream, java.io.OutputStream public final void write(int i) { synchronized (this) { zzks.checkArgument(!this.closed); this.zzzz++; if (this.count < this.zzaaa) { super.write(i); } } } @Override // java.io.ByteArrayOutputStream, java.io.OutputStream public final void write(byte[] bArr, int i, int i2) { synchronized (this) { zzks.checkArgument(!this.closed); this.zzzz += i2; if (this.count < this.zzaaa) { int i3 = this.count + i2; int i4 = this.zzaaa; if (i3 > i4) { i2 += i4 - i3; } super.write(bArr, i, i2); } } } @Override // java.io.ByteArrayOutputStream, java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable public final void close() throws IOException { synchronized (this) { if (!this.closed) { if (this.zzzz != 0) { StringBuilder sb = new StringBuilder("Total: "); zza(sb, this.zzzz); if (this.count != 0 && this.count < this.zzzz) { sb.append(" (logging first "); zza(sb, this.count); sb.append(")"); } this.logger.logp(Level.CONFIG, "o.vqe", "close", sb.toString()); if (this.count != 0) { this.logger.logp(this.zzaab, "o.vqe", "close", toString("UTF-8").replaceAll("[\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F]", " ")); } } this.closed = true; } } } private static void zza(StringBuilder sb, int i) { if (i == 1) { sb.append("1 byte"); } else { sb.append(NumberFormat.getInstance().format(i)); sb.append(" bytes"); } } }