Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
/* loaded from: classes.dex */
public interface DiskUsage {
void a(File file);
}

View File

@@ -0,0 +1,6 @@
package com.baidu.cloud.videocache.file;
/* loaded from: classes.dex */
public interface FileNameGenerator {
String a(String str);
}

View File

@@ -0,0 +1,105 @@
package com.baidu.cloud.videocache.file;
import com.baidu.cloud.videocache.Cache;
import com.baidu.cloud.videocache.x;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
/* loaded from: classes.dex */
public class a implements Cache {
private final DiskUsage a;
public File b;
private RandomAccessFile c;
public a(File file, DiskUsage diskUsage) {
File file2;
try {
if (diskUsage == null) {
throw new NullPointerException();
}
this.a = diskUsage;
b.a(file.getParentFile());
boolean exists = file.exists();
if (exists) {
file2 = file;
} else {
file2 = new File(file.getParentFile(), file.getName() + ".download");
}
this.b = file2;
this.c = new RandomAccessFile(this.b, exists ? "r" : "rw");
} catch (IOException e) {
throw new x("Error using file " + file + " as disc cache", e);
}
}
private boolean a(File file) {
return file.getName().endsWith(".download");
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized int a(byte[] bArr, long j, int i) {
try {
this.c.seek(j);
} catch (IOException e) {
throw new x(String.format("Error reading %d bytes with offset %d from file[%d bytes] to buffer[%d bytes]", Integer.valueOf(i), Long.valueOf(j), Long.valueOf(available()), Integer.valueOf(bArr.length)), e);
}
return this.c.read(bArr, 0, i);
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized void a() {
if (b()) {
return;
}
close();
File file = new File(this.b.getParentFile(), this.b.getName().substring(0, this.b.getName().length() - 9));
if (!this.b.renameTo(file)) {
throw new x("Error renaming file " + this.b + " to " + file + " for completion!");
}
this.b = file;
try {
this.c = new RandomAccessFile(this.b, "r");
this.a.a(this.b);
} catch (IOException e) {
throw new x("Error opening " + this.b + " as disc cache", e);
}
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized void a(byte[] bArr, int i) {
try {
if (b()) {
throw new x("Error append cache: cache file " + this.b + " is completed!");
}
this.c.seek(available());
this.c.write(bArr, 0, i);
} catch (IOException e) {
throw new x(String.format("Error writing %d bytes to %s from buffer with size %d", Integer.valueOf(i), this.c, Integer.valueOf(bArr.length)), e);
}
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized long available() {
try {
} catch (IOException e) {
throw new x("Error reading length of file " + this.b, e);
}
return (int) this.c.length();
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized boolean b() {
return !a(this.b);
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized void close() {
try {
this.c.close();
this.a.a(this.b);
} catch (IOException e) {
throw new x("Error closing file " + this.b, e);
}
}
}

View File

@@ -0,0 +1,76 @@
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);
}
}

View File

@@ -0,0 +1,23 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.util.Comparator;
/* loaded from: classes.dex */
final class d implements Comparator {
private d() {
}
private int a(long j, long j2) {
if (j < j2) {
return -1;
}
return j == j2 ? 0 : 1;
}
@Override // java.util.Comparator
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public int compare(File file, File file2) {
return a(file.lastModified(), file2.lastModified());
}
}

View File

@@ -0,0 +1,56 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public abstract class e implements DiskUsage {
private static final Logger b = LoggerFactory.getLogger("LruDiskUsage");
private final ExecutorService a = Executors.newSingleThreadExecutor();
private void a(List list) {
long b2 = b(list);
int size = list.size();
Iterator it = list.iterator();
while (it.hasNext()) {
File file = (File) it.next();
if (!a(file, b2, size)) {
long length = file.length();
if (file.delete()) {
size--;
b2 -= length;
b.info("Cache file " + file + " is deleted because it exceeds cache limit");
} else {
b.error("Error deleting file " + file + " for trimming cache");
}
}
}
}
private long b(List list) {
Iterator it = list.iterator();
long j = 0;
while (it.hasNext()) {
j += ((File) it.next()).length();
}
return j;
}
/* JADX INFO: Access modifiers changed from: private */
public void b(File file) {
b.c(file);
a(b.b(file.getParentFile()));
}
@Override // com.baidu.cloud.videocache.file.DiskUsage
public void a(File file) {
this.a.submit(new f(this, file));
}
protected abstract boolean a(File file, long j, int i);
}

View File

@@ -0,0 +1,22 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.util.concurrent.Callable;
/* loaded from: classes.dex */
class f implements Callable {
private final File a;
final /* synthetic */ e b;
public f(e eVar, File file) {
this.b = eVar;
this.a = file;
}
@Override // java.util.concurrent.Callable
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public Void call() {
this.b.b(this.a);
return null;
}
}

View File

@@ -0,0 +1,20 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
/* loaded from: classes.dex */
public class g extends e {
private final long c;
public g(long j) {
if (j <= 0) {
throw new IllegalArgumentException("Max size must be positive number!");
}
this.c = j;
}
@Override // com.baidu.cloud.videocache.file.e
protected boolean a(File file, long j, int i) {
return j <= this.c;
}
}

View File

@@ -0,0 +1,11 @@
package com.baidu.cloud.videocache.file;
import com.baidu.cloud.videocache.z;
/* loaded from: classes.dex */
public class h implements FileNameGenerator {
@Override // com.baidu.cloud.videocache.file.FileNameGenerator
public String a(String str) {
return z.b(str);
}
}