mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 09:27:16 +01:00
145 lines
5.1 KiB
Java
145 lines
5.1 KiB
Java
package com.bumptech.glide.disklrucache;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.Closeable;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.nio.charset.Charset;
|
|
import okio.Buffer$$ExternalSyntheticBUOutline0;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes6.dex */
|
|
class StrictLineReader implements Closeable {
|
|
private static final byte CR = 13;
|
|
private static final byte LF = 10;
|
|
private byte[] buf;
|
|
private final Charset charset;
|
|
private int end;
|
|
private final InputStream in;
|
|
private int pos;
|
|
|
|
public StrictLineReader(InputStream inputStream, int i, Charset charset) {
|
|
if (inputStream == null || charset == null) {
|
|
throw null;
|
|
}
|
|
if (i < 0) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("capacity <= 0");
|
|
throw null;
|
|
}
|
|
if (!charset.equals(Util.US_ASCII)) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Unsupported encoding");
|
|
throw null;
|
|
}
|
|
this.in = inputStream;
|
|
this.charset = charset;
|
|
this.buf = new byte[i];
|
|
}
|
|
|
|
private void fillBuf() throws IOException {
|
|
InputStream inputStream = this.in;
|
|
byte[] bArr = this.buf;
|
|
int read = inputStream.read(bArr, 0, bArr.length);
|
|
if (read == -1) {
|
|
Buffer$$ExternalSyntheticBUOutline0.m$3();
|
|
} else {
|
|
this.pos = 0;
|
|
this.end = read;
|
|
}
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() throws IOException {
|
|
synchronized (this.in) {
|
|
try {
|
|
if (this.buf != null) {
|
|
this.buf = null;
|
|
this.in.close();
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean hasUnterminatedLine() {
|
|
return this.end == -1;
|
|
}
|
|
|
|
public String readLine() throws IOException {
|
|
int i;
|
|
byte[] bArr;
|
|
int i2;
|
|
synchronized (this.in) {
|
|
try {
|
|
if (this.buf == null) {
|
|
throw new IOException("LineReader is closed");
|
|
}
|
|
if (this.pos >= this.end) {
|
|
fillBuf();
|
|
}
|
|
for (int i3 = this.pos; i3 != this.end; i3++) {
|
|
byte[] bArr2 = this.buf;
|
|
if (bArr2[i3] == 10) {
|
|
int i4 = this.pos;
|
|
if (i3 != i4) {
|
|
i2 = i3 - 1;
|
|
if (bArr2[i2] == 13) {
|
|
String str = new String(bArr2, i4, i2 - i4, this.charset.name());
|
|
this.pos = i3 + 1;
|
|
return str;
|
|
}
|
|
}
|
|
i2 = i3;
|
|
String str2 = new String(bArr2, i4, i2 - i4, this.charset.name());
|
|
this.pos = i3 + 1;
|
|
return str2;
|
|
}
|
|
}
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((this.end - this.pos) + 80) { // from class: com.bumptech.glide.disklrucache.StrictLineReader.1
|
|
@Override // java.io.ByteArrayOutputStream
|
|
public String toString() {
|
|
int i5 = ((ByteArrayOutputStream) this).count;
|
|
if (i5 > 0 && ((ByteArrayOutputStream) this).buf[i5 - 1] == 13) {
|
|
i5--;
|
|
}
|
|
try {
|
|
return new String(((ByteArrayOutputStream) this).buf, 0, i5, StrictLineReader.this.charset.name());
|
|
} catch (UnsupportedEncodingException e) {
|
|
Buffer$$ExternalSyntheticBUOutline0.m((Object) e);
|
|
return null;
|
|
}
|
|
}
|
|
};
|
|
loop1: while (true) {
|
|
byte[] bArr3 = this.buf;
|
|
int i5 = this.pos;
|
|
byteArrayOutputStream.write(bArr3, i5, this.end - i5);
|
|
this.end = -1;
|
|
fillBuf();
|
|
i = this.pos;
|
|
while (i != this.end) {
|
|
bArr = this.buf;
|
|
if (bArr[i] == 10) {
|
|
break loop1;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
int i6 = this.pos;
|
|
if (i != i6) {
|
|
byteArrayOutputStream.write(bArr, i6, i - i6);
|
|
}
|
|
this.pos = i + 1;
|
|
return byteArrayOutputStream.toString();
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public StrictLineReader(InputStream inputStream, Charset charset) {
|
|
this(inputStream, 8192, charset);
|
|
}
|
|
}
|