jimu-decompiled/sources/com/bumptech/glide/util/ContentLengthInputStream.java
2025-05-13 19:24:51 +02:00

56 lines
1.7 KiB
Java

package com.bumptech.glide.util;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes.dex */
public final class ContentLengthInputStream extends FilterInputStream {
private final long a;
private int b;
private ContentLengthInputStream(InputStream inputStream, long j) {
super(inputStream);
this.a = j;
}
public static InputStream a(InputStream inputStream, long j) {
return new ContentLengthInputStream(inputStream, j);
}
@Override // java.io.FilterInputStream, java.io.InputStream
public synchronized int available() throws IOException {
return (int) Math.max(this.a - this.b, ((FilterInputStream) this).in.available());
}
@Override // java.io.FilterInputStream, java.io.InputStream
public synchronized int read() throws IOException {
int read;
read = super.read();
a(read >= 0 ? 1 : -1);
return read;
}
private int a(int i) throws IOException {
if (i >= 0) {
this.b += i;
} else if (this.a - this.b > 0) {
throw new IOException("Failed to read all expected data, expected: " + this.a + ", but read: " + this.b);
}
return i;
}
@Override // java.io.FilterInputStream, java.io.InputStream
public int read(byte[] bArr) throws IOException {
return read(bArr, 0, bArr.length);
}
@Override // java.io.FilterInputStream, java.io.InputStream
public synchronized int read(byte[] bArr, int i, int i2) throws IOException {
int read;
read = super.read(bArr, i, i2);
a(read);
return read;
}
}