- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
82 lines
2.5 KiB
Java
82 lines
2.5 KiB
Java
package com.singular.sdk.internal;
|
|
|
|
import android.content.Context;
|
|
import com.singular.sdk.internal.QueueFile;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.File;
|
|
import java.io.OutputStreamWriter;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public final class FixedSizePersistentQueue implements Queue {
|
|
public static final SingularLog logger = SingularLog.getLogger(FixedSizePersistentQueue.class.getSimpleName());
|
|
public final int MAX_SIZE;
|
|
public final DirectByteArrayOutputStream bytes = new DirectByteArrayOutputStream();
|
|
public final QueueFile queueFile;
|
|
|
|
public static class DirectByteArrayOutputStream extends ByteArrayOutputStream {
|
|
public byte[] getArray() {
|
|
return ((ByteArrayOutputStream) this).buf;
|
|
}
|
|
}
|
|
|
|
public static FixedSizePersistentQueue create(Context context, String str, int i) {
|
|
File file = new File(context.getFilesDir(), str);
|
|
if (file.exists()) {
|
|
logger.debug("FYI - file %s already exists, will reuse.", file.getName());
|
|
}
|
|
return new FixedSizePersistentQueue(new QueueFile.Builder(file).build(), i);
|
|
}
|
|
|
|
public FixedSizePersistentQueue(QueueFile queueFile, int i) {
|
|
this.queueFile = queueFile;
|
|
this.MAX_SIZE = i;
|
|
}
|
|
|
|
public synchronized int size() {
|
|
return this.queueFile.size();
|
|
}
|
|
|
|
public synchronized boolean isEmpty() {
|
|
return size() == 0;
|
|
}
|
|
|
|
@Override // com.singular.sdk.internal.Queue
|
|
public synchronized void add(String str) {
|
|
try {
|
|
if (Utils.isEmptyOrNull(str)) {
|
|
return;
|
|
}
|
|
if (this.queueFile.size() >= this.MAX_SIZE) {
|
|
this.queueFile.remove(1);
|
|
}
|
|
this.bytes.reset();
|
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(this.bytes);
|
|
outputStreamWriter.write(str);
|
|
outputStreamWriter.close();
|
|
this.queueFile.add(this.bytes.getArray(), 0, this.bytes.size());
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // com.singular.sdk.internal.Queue
|
|
public synchronized String peek() {
|
|
byte[] peek = this.queueFile.peek();
|
|
if (peek == null) {
|
|
return null;
|
|
}
|
|
return new String(peek, "UTF-8");
|
|
}
|
|
|
|
@Override // com.singular.sdk.internal.Queue
|
|
public synchronized void remove() {
|
|
remove(1);
|
|
}
|
|
|
|
public synchronized void remove(int i) {
|
|
if (i <= size()) {
|
|
this.queueFile.remove(i);
|
|
}
|
|
}
|
|
}
|