clean up code for posh cache
This commit is contained in:
parent
8b90c1c498
commit
4ac64f3a3b
|
@ -590,20 +590,11 @@ public class MemorizingTrustManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getPoshFingerprintsFromCache(String domain) {
|
private List<String> getPoshFingerprintsFromCache(String domain) {
|
||||||
File file = getPoshCacheFile(domain);
|
final File file = getPoshCacheFile(domain);
|
||||||
try {
|
try {
|
||||||
InputStream is = new FileInputStream(file);
|
final InputStream inputStream = new FileInputStream(file);
|
||||||
BufferedReader buf = new BufferedReader(new InputStreamReader(is));
|
final String json = CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
|
||||||
|
final JSONObject jsonObject = new JSONObject(json);
|
||||||
String line = buf.readLine();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
while (line != null) {
|
|
||||||
sb.append(line).append("\n");
|
|
||||||
line = buf.readLine();
|
|
||||||
}
|
|
||||||
JSONObject jsonObject = new JSONObject(sb.toString());
|
|
||||||
is.close();
|
|
||||||
long expires = jsonObject.getLong("expires");
|
long expires = jsonObject.getLong("expires");
|
||||||
long expiresIn = expires - System.currentTimeMillis();
|
long expiresIn = expires - System.currentTimeMillis();
|
||||||
if (expiresIn < 0) {
|
if (expiresIn < 0) {
|
||||||
|
@ -612,15 +603,13 @@ public class MemorizingTrustManager {
|
||||||
} else {
|
} else {
|
||||||
Log.d("mtm", "posh fingerprints expire in " + (expiresIn / 1000) + "s");
|
Log.d("mtm", "posh fingerprints expire in " + (expiresIn / 1000) + "s");
|
||||||
}
|
}
|
||||||
List<String> result = new ArrayList<>();
|
final List<String> result = new ArrayList<>();
|
||||||
JSONArray jsonArray = jsonObject.getJSONArray("fingerprints");
|
final JSONArray jsonArray = jsonObject.getJSONArray("fingerprints");
|
||||||
for (int i = 0; i < jsonArray.length(); ++i) {
|
for (int i = 0; i < jsonArray.length(); ++i) {
|
||||||
result.add(jsonArray.getString(i));
|
result.add(jsonArray.getString(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (final IOException e) {
|
||||||
return null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
return null;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
Loading…
Reference in a new issue