first commit
[bylock.git] / sources / com / google / android / gms / d / db.java
blobac85ce44c602851fab6801449f7b444593276481
1 package com.google.android.gms.d;
3 import android.content.Context;
4 import android.content.res.Resources;
5 import com.google.android.gms.internal.df;
6 import com.google.android.gms.internal.dz;
7 import com.google.android.gms.internal.ea;
8 import com.google.android.gms.internal.n;
9 import java.io.ByteArrayOutputStream;
10 import java.io.File;
11 import java.io.FileInputStream;
12 import java.io.FileNotFoundException;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.UnsupportedEncodingException;
17 import java.util.concurrent.ExecutorService;
18 import java.util.concurrent.Executors;
19 import org.json.JSONException;
21 /* access modifiers changed from: package-private */
22 public class db implements ft {
23 private final Context a;
24 private final String b;
25 private final ExecutorService c = Executors.newSingleThreadExecutor();
26 private bi d;
28 db(Context context, String str) {
29 this.a = context;
30 this.b = str;
33 private di a(ByteArrayOutputStream byteArrayOutputStream) {
34 try {
35 return bb.a(byteArrayOutputStream.toString("UTF-8"));
36 } catch (UnsupportedEncodingException e) {
37 bk.d("Tried to convert binary resource to string for JSON parsing; not UTF-8 format");
38 return null;
39 } catch (JSONException e2) {
40 bk.b("Resource is a UTF-8 encoded string but doesn't contain a JSON container");
41 return null;
45 private di a(byte[] bArr) {
46 try {
47 return de.a(n.a(bArr));
48 } catch (dz e) {
49 bk.b("Resource doesn't contain a binary container");
50 return null;
51 } catch (dm e2) {
52 bk.b("Resource doesn't contain a binary container");
53 return null;
57 @Override // com.google.android.gms.d.ft
58 public di a(int i) {
59 bk.e("Atttempting to load container from resource ID " + i);
60 try {
61 InputStream openRawResource = this.a.getResources().openRawResource(i);
62 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
63 de.a(openRawResource, byteArrayOutputStream);
64 di a2 = a(byteArrayOutputStream);
65 return a2 != null ? a2 : a(byteArrayOutputStream.toByteArray());
66 } catch (IOException e) {
67 bk.b("Error reading default container resource with ID " + i);
68 return null;
69 } catch (Resources.NotFoundException e2) {
70 bk.b("No default container resource found.");
71 return null;
75 @Override // com.google.android.gms.common.api.d
76 public synchronized void a() {
77 this.c.shutdown();
80 @Override // com.google.android.gms.d.ft
81 public void a(bi biVar) {
82 this.d = biVar;
85 @Override // com.google.android.gms.d.ft
86 public void a(df dfVar) {
87 this.c.execute(new dd(this, dfVar));
90 @Override // com.google.android.gms.d.ft
91 public void b() {
92 this.c.execute(new dc(this));
95 /* access modifiers changed from: package-private */
96 public boolean b(df dfVar) {
97 boolean z = false;
98 File d2 = d();
99 try {
100 FileOutputStream fileOutputStream = new FileOutputStream(d2);
101 try {
102 fileOutputStream.write(ea.a(dfVar));
103 z = true;
104 try {
105 fileOutputStream.close();
106 } catch (IOException e) {
107 bk.b("error closing stream for writing resource to disk");
109 } catch (IOException e2) {
110 bk.b("Error writing resource to disk. Removing resource from disk.");
111 d2.delete();
112 try {
113 fileOutputStream.close();
114 } catch (IOException e3) {
115 bk.b("error closing stream for writing resource to disk");
117 } catch (Throwable th) {
118 try {
119 fileOutputStream.close();
120 } catch (IOException e4) {
121 bk.b("error closing stream for writing resource to disk");
123 throw th;
125 } catch (FileNotFoundException e5) {
126 bk.a("Error opening resource file for writing");
128 return z;
131 /* access modifiers changed from: package-private */
132 public void c() {
133 if (this.d == null) {
134 throw new IllegalStateException("callback must be set before execute");
136 this.d.a();
137 bk.e("Start loading resource from disk ...");
138 if ((ck.a().b() == cl.CONTAINER || ck.a().b() == cl.CONTAINER_DEBUG) && this.b.equals(ck.a().d())) {
139 this.d.a(bj.NOT_AVAILABLE);
140 return;
142 try {
143 FileInputStream fileInputStream = new FileInputStream(d());
144 try {
145 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
146 de.a(fileInputStream, byteArrayOutputStream);
147 this.d.a(df.a(byteArrayOutputStream.toByteArray()));
148 try {
149 fileInputStream.close();
150 } catch (IOException e) {
151 bk.b("error closing stream for reading resource from disk");
153 } catch (IOException e2) {
154 bk.b("error reading resource from disk");
155 this.d.a(bj.IO_ERROR);
156 try {
157 fileInputStream.close();
158 } catch (IOException e3) {
159 bk.b("error closing stream for reading resource from disk");
161 } catch (Throwable th) {
162 try {
163 fileInputStream.close();
164 } catch (IOException e4) {
165 bk.b("error closing stream for reading resource from disk");
167 throw th;
169 bk.e("Load resource from disk finished.");
170 } catch (FileNotFoundException e5) {
171 bk.d("resource not on disk");
172 this.d.a(bj.NOT_AVAILABLE);
176 /* access modifiers changed from: package-private */
177 public File d() {
178 return new File(this.a.getDir("google_tagmanager", 0), "resource_" + this.b);