This commit is contained in:
Andrea Cavalli 2022-10-10 21:51:16 +02:00
parent dbcdbaafeb
commit 3a48d63b11
2 changed files with 17 additions and 2 deletions

View File

@ -4,7 +4,7 @@
<groupId>it.cavallium</groupId>
<artifactId>filequeue</artifactId>
<name>file queue project</name>
<version>3.0.0</version>
<version>3.0.2</version>
<packaging>jar</packaging>
<description>Light weight, high performance, simple, reliable and persistent queue</description>
<modelVersion>4.0.0</modelVersion>

View File

@ -2,6 +2,7 @@ package it.cavallium.filequeue;
import com.squareup.tape2.QueueFile;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public final class DiskQueueToConsumer<T> implements IQueueToConsumer<T> {
@ -10,10 +11,24 @@ public final class DiskQueueToConsumer<T> implements IQueueToConsumer<T> {
private final QueueFile queueFile;
public DiskQueueToConsumer(Path file,
boolean clear,
Serializer<T> serializer,
Deserializer<T> deserializer,
QueueConsumer<T> consumer) throws IOException {
QueueFile queueFile = new QueueFile.Builder(file.toFile()).build();
QueueFile queueFile;
try {
queueFile = new QueueFile.Builder(file.toFile()).zero(false).build();
if (clear) {
queueFile.clear();
}
} catch (Throwable ex) {
try {
Files.deleteIfExists(file);
} catch (Throwable ex2) {
}
queueFile = new QueueFile.Builder(file.toFile()).zero(false).build();
}
this.queueFile = queueFile;
this.queue = new QueueToConsumer<>(new SimpleQueueFile<>(queueFile, serializer, deserializer), consumer);
}