package com.liulishuo.filedownloader.message; import com.liulishuo.filedownloader.BaseDownloadTask; import com.liulishuo.filedownloader.download.DownloadStatusCallback; import com.liulishuo.filedownloader.message.BlockCompleteMessage; import com.liulishuo.filedownloader.message.LargeMessageSnapshot; import com.liulishuo.filedownloader.message.MessageSnapshot; import com.liulishuo.filedownloader.message.SmallMessageSnapshot; import com.liulishuo.filedownloader.model.FileDownloadModel; import com.liulishuo.filedownloader.util.FileDownloadLog; import com.liulishuo.filedownloader.util.FileDownloadUtils; import java.io.File; /* loaded from: classes.dex */ public class MessageSnapshotTaker { public static MessageSnapshot a(int i, File file, boolean z) { long length = file.length(); return length > 2147483647L ? z ? new LargeMessageSnapshot.CompletedFlowDirectlySnapshot(i, true, length) : new LargeMessageSnapshot.CompletedSnapshot(i, true, length) : z ? new SmallMessageSnapshot.CompletedFlowDirectlySnapshot(i, true, (int) length) : new SmallMessageSnapshot.CompletedSnapshot(i, true, (int) length); } public static MessageSnapshot a(int i, long j, long j2, boolean z) { if (j2 > 2147483647L) { if (z) { return new LargeMessageSnapshot.WarnFlowDirectlySnapshot(i, j, j2); } return new LargeMessageSnapshot.WarnMessageSnapshot(i, j, j2); } if (z) { return new SmallMessageSnapshot.WarnFlowDirectlySnapshot(i, (int) j, (int) j2); } return new SmallMessageSnapshot.WarnMessageSnapshot(i, (int) j, (int) j2); } public static MessageSnapshot a(int i, long j, Throwable th) { if (j > 2147483647L) { return new LargeMessageSnapshot.ErrorMessageSnapshot(i, j, th); } return new SmallMessageSnapshot.ErrorMessageSnapshot(i, (int) j, th); } public static MessageSnapshot a(BaseDownloadTask baseDownloadTask) { if (baseDownloadTask.e()) { return new LargeMessageSnapshot.PausedSnapshot(baseDownloadTask.getId(), baseDownloadTask.l(), baseDownloadTask.t()); } return new SmallMessageSnapshot.PausedSnapshot(baseDownloadTask.getId(), baseDownloadTask.r(), baseDownloadTask.f()); } public static MessageSnapshot a(MessageSnapshot messageSnapshot) { if (messageSnapshot.getStatus() == -3) { return new BlockCompleteMessage.BlockCompleteMessageImpl(messageSnapshot); } throw new IllegalStateException(FileDownloadUtils.a("take block completed snapshot, must has already be completed. %d %d", Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(messageSnapshot.getStatus()))); } public static MessageSnapshot a(byte b, FileDownloadModel fileDownloadModel, DownloadStatusCallback.ProcessParams processParams) { MessageSnapshot errorMessageSnapshot; IllegalStateException illegalStateException; int id = fileDownloadModel.getId(); if (b == -4) { throw new IllegalStateException(FileDownloadUtils.a("please use #catchWarn instead %d", Integer.valueOf(id))); } if (b == -3) { if (fileDownloadModel.isLargeFile()) { return new LargeMessageSnapshot.CompletedSnapshot(id, false, fileDownloadModel.getTotal()); } return new SmallMessageSnapshot.CompletedSnapshot(id, false, (int) fileDownloadModel.getTotal()); } if (b != -1) { if (b != 1) { if (b == 2) { String filename = fileDownloadModel.isPathAsDirectory() ? fileDownloadModel.getFilename() : null; if (fileDownloadModel.isLargeFile()) { return new LargeMessageSnapshot.ConnectedMessageSnapshot(id, processParams.c(), fileDownloadModel.getTotal(), fileDownloadModel.getETag(), filename); } return new SmallMessageSnapshot.ConnectedMessageSnapshot(id, processParams.c(), (int) fileDownloadModel.getTotal(), fileDownloadModel.getETag(), filename); } if (b == 3) { if (fileDownloadModel.isLargeFile()) { return new LargeMessageSnapshot.ProgressMessageSnapshot(id, fileDownloadModel.getSoFar()); } return new SmallMessageSnapshot.ProgressMessageSnapshot(id, (int) fileDownloadModel.getSoFar()); } if (b != 5) { if (b != 6) { String a = FileDownloadUtils.a("it can't takes a snapshot for the task(%s) when its status is %d,", fileDownloadModel, Byte.valueOf(b)); FileDownloadLog.e(MessageSnapshotTaker.class, "it can't takes a snapshot for the task(%s) when its status is %d,", fileDownloadModel, Byte.valueOf(b)); if (processParams.a() != null) { illegalStateException = new IllegalStateException(a, processParams.a()); } else { illegalStateException = new IllegalStateException(a); } if (fileDownloadModel.isLargeFile()) { return new LargeMessageSnapshot.ErrorMessageSnapshot(id, fileDownloadModel.getSoFar(), illegalStateException); } return new SmallMessageSnapshot.ErrorMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), illegalStateException); } return new MessageSnapshot.StartedMessageSnapshot(id); } if (fileDownloadModel.isLargeFile()) { errorMessageSnapshot = new LargeMessageSnapshot.RetryMessageSnapshot(id, fileDownloadModel.getSoFar(), processParams.a(), processParams.b()); } else { errorMessageSnapshot = new SmallMessageSnapshot.RetryMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), processParams.a(), processParams.b()); } } else if (fileDownloadModel.isLargeFile()) { errorMessageSnapshot = new LargeMessageSnapshot.PendingMessageSnapshot(id, fileDownloadModel.getSoFar(), fileDownloadModel.getTotal()); } else { return new SmallMessageSnapshot.PendingMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), (int) fileDownloadModel.getTotal()); } } else if (fileDownloadModel.isLargeFile()) { errorMessageSnapshot = new LargeMessageSnapshot.ErrorMessageSnapshot(id, fileDownloadModel.getSoFar(), processParams.a()); } else { errorMessageSnapshot = new SmallMessageSnapshot.ErrorMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), processParams.a()); } return errorMessageSnapshot; } }