package com.orhanobut.logger; import android.os.Handler; import android.os.Looper; import android.os.Message; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; /* loaded from: classes.dex */ public class DiskLogStrategy implements LogStrategy { private final Handler a; public DiskLogStrategy(Handler handler) { Utils.a(handler); this.a = handler; } @Override // com.orhanobut.logger.LogStrategy public void a(int i, String str, String str2) { Utils.a(str2); Handler handler = this.a; handler.sendMessage(handler.obtainMessage(i, str2)); } static class WriteHandler extends Handler { private final String a; private final int b; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ WriteHandler(Looper looper, String str, int i) { super(looper); Utils.a(looper); Utils.a(str); this.a = str; this.b = i; } private void a(FileWriter fileWriter, String str) throws IOException { Utils.a(fileWriter); Utils.a(str); fileWriter.append((CharSequence) str); } @Override // android.os.Handler public void handleMessage(Message message) { FileWriter fileWriter; String str = (String) message.obj; try { fileWriter = new FileWriter(a(this.a, new SimpleDateFormat("yyyy-MM-dd").format(new Date())), true); try { a(fileWriter, str); fileWriter.flush(); fileWriter.close(); } catch (IOException unused) { if (fileWriter != null) { try { fileWriter.flush(); fileWriter.close(); } catch (IOException unused2) { } } } } catch (IOException unused3) { fileWriter = null; } } private File a(String str, String str2) { File file; Utils.a(str); Utils.a(str2); File file2 = new File(str); if (!file2.exists()) { file2.mkdirs(); } File file3 = null; File file4 = new File(file2, String.format("%s_%s.csv", str2, 0)); int i = 0; while (true) { File file5 = file4; file = file3; file3 = file5; if (!file3.exists()) { break; } i++; file4 = new File(file2, String.format("%s_%s.csv", str2, Integer.valueOf(i))); } return (file == null || file.length() >= ((long) this.b)) ? file3 : file; } } }