package com.baidu.cloud.videocache.file; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.LinkedList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /* loaded from: classes.dex */ class b { private static final Logger a = LoggerFactory.getLogger("Files"); static void a(File file) { if (!file.exists()) { if (!file.mkdirs()) { throw new IOException(String.format("Directory %s can't be created", file.getAbsolutePath())); } } else { if (file.isDirectory()) { return; } throw new IOException("File " + file + " is not directory!"); } } static List b(File file) { LinkedList linkedList = new LinkedList(); File[] listFiles = file.listFiles(); if (listFiles == null) { return linkedList; } List asList = Arrays.asList(listFiles); Collections.sort(asList, new d()); return asList; } static void c(File file) { if (file.exists()) { long currentTimeMillis = System.currentTimeMillis(); if (file.setLastModified(currentTimeMillis)) { return; } d(file); if (file.lastModified() < currentTimeMillis) { a.warn("Last modified date {} is not set for file {}", new Date(file.lastModified()), file.getAbsolutePath()); } } } static void d(File file) { long length = file.length(); if (length == 0) { e(file); return; } RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rwd"); long j = length - 1; randomAccessFile.seek(j); byte readByte = randomAccessFile.readByte(); randomAccessFile.seek(j); randomAccessFile.write(readByte); randomAccessFile.close(); } private static void e(File file) { if (file.delete() && file.createNewFile()) { return; } throw new IOException("Error recreate zero-size file " + file); } }