- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
class CircuitBreaker
{
boolean broken = false;
CircuitBreaker() {}
private void breakCircuit()
{
this.broken = true;
}
private boolean isBroken()
{
return this.broken;
}
}
private boolean writeAssetsToDisk()
{
CircuitBreaker breaker = new CircuitBreaker();
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
return !breaker.isBroken();
}
private void writeBase64EncodedAssetToDisk(CircuitBreaker breaker, String base64String, String filename)
{
if (breaker.isBroken()) {
return;
}
...
try
{
...
}
catch (IOException e)
{
breaker.breakCircuit(); return;
}
...
}
Используй исключения, Люк. Фрагмент из Amazon Mobile Ads SDK.