mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
78 lines
2.5 KiB
Java
78 lines
2.5 KiB
Java
package com.airbnb.lottie.network;
|
|
|
|
import com.airbnb.lottie.utils.Logger;
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class DefaultLottieFetchResult implements LottieFetchResult {
|
|
private final HttpURLConnection connection;
|
|
|
|
public DefaultLottieFetchResult(HttpURLConnection httpURLConnection) {
|
|
this.connection = httpURLConnection;
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.network.LottieFetchResult
|
|
public boolean isSuccessful() {
|
|
try {
|
|
return this.connection.getResponseCode() / 100 == 2;
|
|
} catch (IOException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.network.LottieFetchResult
|
|
public InputStream bodyByteStream() throws IOException {
|
|
return this.connection.getInputStream();
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.network.LottieFetchResult
|
|
public String contentType() {
|
|
return this.connection.getContentType();
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.network.LottieFetchResult
|
|
public String error() {
|
|
try {
|
|
if (isSuccessful()) {
|
|
return null;
|
|
}
|
|
return "Unable to fetch " + this.connection.getURL() + ". Failed with " + this.connection.getResponseCode() + "\n" + getErrorFromConnection(this.connection);
|
|
} catch (IOException e) {
|
|
Logger.warning("get error failed ", e);
|
|
return e.getMessage();
|
|
}
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() {
|
|
this.connection.disconnect();
|
|
}
|
|
|
|
private String getErrorFromConnection(HttpURLConnection httpURLConnection) throws IOException {
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getErrorStream()));
|
|
StringBuilder sb = new StringBuilder();
|
|
while (true) {
|
|
try {
|
|
String readLine = bufferedReader.readLine();
|
|
if (readLine != null) {
|
|
sb.append(readLine).append('\n');
|
|
} else {
|
|
try {
|
|
break;
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
} finally {
|
|
try {
|
|
bufferedReader.close();
|
|
} catch (Exception unused2) {
|
|
}
|
|
}
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|