package com.google.firebase.remoteconfig.internal; import android.content.Context; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes.dex */ public class ConfigStorageClient { private static final Map clientInstances = new HashMap(); private final Context context; private final String fileName; private ConfigStorageClient(Context context, String str) { this.context = context; this.fileName = str; } public Void write(ConfigContainer configContainer) throws IOException { synchronized (this) { FileOutputStream openFileOutput = this.context.openFileOutput(this.fileName, 0); try { openFileOutput.write(configContainer.toString().getBytes("UTF-8")); } finally { openFileOutput.close(); } } return null; } public ConfigContainer read() throws IOException { FileInputStream fileInputStream; synchronized (this) { FileInputStream fileInputStream2 = null; try { fileInputStream = this.context.openFileInput(this.fileName); } catch (FileNotFoundException | JSONException unused) { fileInputStream = null; } catch (Throwable th) { th = th; } try { int available = fileInputStream.available(); byte[] bArr = new byte[available]; fileInputStream.read(bArr, 0, available); ConfigContainer copyOf = ConfigContainer.copyOf(new JSONObject(new String(bArr, "UTF-8"))); if (fileInputStream != null) { fileInputStream.close(); } return copyOf; } catch (FileNotFoundException | JSONException unused2) { if (fileInputStream != null) { fileInputStream.close(); } return null; } catch (Throwable th2) { th = th2; fileInputStream2 = fileInputStream; if (fileInputStream2 != null) { fileInputStream2.close(); } throw th; } } } public Void clear() { synchronized (this) { this.context.deleteFile(this.fileName); } return null; } public static ConfigStorageClient getInstance(Context context, String str) { ConfigStorageClient configStorageClient; synchronized (ConfigStorageClient.class) { Map map = clientInstances; if (!map.containsKey(str)) { map.put(str, new ConfigStorageClient(context, str)); } configStorageClient = map.get(str); } return configStorageClient; } /* JADX INFO: Access modifiers changed from: package-private */ public String getFileName() { return this.fileName; } }