From 3a48d63b113131c9e50e786ff1de8e2780ff04cb Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 10 Oct 2022 21:51:16 +0200 Subject: [PATCH] Update --- pom.xml | 2 +- .../filequeue/DiskQueueToConsumer.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c262a01..fe640e5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ it.cavallium filequeue file queue project - 3.0.0 + 3.0.2 jar Light weight, high performance, simple, reliable and persistent queue 4.0.0 diff --git a/src/main/java/it/cavallium/filequeue/DiskQueueToConsumer.java b/src/main/java/it/cavallium/filequeue/DiskQueueToConsumer.java index fdd61bd..917516e 100644 --- a/src/main/java/it/cavallium/filequeue/DiskQueueToConsumer.java +++ b/src/main/java/it/cavallium/filequeue/DiskQueueToConsumer.java @@ -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 implements IQueueToConsumer { @@ -10,10 +11,24 @@ public final class DiskQueueToConsumer implements IQueueToConsumer { private final QueueFile queueFile; public DiskQueueToConsumer(Path file, + boolean clear, Serializer serializer, Deserializer deserializer, QueueConsumer 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); }