From be20e2b17af66b05e16ed04092aad92812c8022a Mon Sep 17 00:00:00 2001 From: Szum123321 Date: Fri, 12 May 2023 18:47:54 +0200 Subject: [PATCH] some cleanup --- .../szum123321/textile_backup/Globals.java | 29 ++++++++++++++++++- .../core/create/BrokenFileHandler.java | 4 +-- .../core/create/ExecutableBackup.java | 5 ++-- .../textile_backup/core/digest/Hash.java | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/Globals.java b/src/main/java/net/szum123321/textile_backup/Globals.java index 26beea8..2567528 100644 --- a/src/main/java/net/szum123321/textile_backup/Globals.java +++ b/src/main/java/net/szum123321/textile_backup/Globals.java @@ -26,6 +26,8 @@ import net.szum123321.textile_backup.core.Utilities; import net.szum123321.textile_backup.core.restore.AwaitThread; import org.apache.commons.io.FileUtils; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.file.Files; import java.nio.file.Path; import java.time.format.DateTimeFormatter; @@ -36,12 +38,37 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; +import java.util.zip.CRC32; public class Globals { public static final Globals INSTANCE = new Globals(); private static final TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); public static final DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss"); - public static final Supplier CHECKSUM_SUPPLIER = BalticHash::new; + public static final Supplier CHECKSUM_SUPPLIER = BalticHash::new;/*() -> new Hash() { + private final CRC32 crc = new CRC32(); + + @Override + public void update ( int b){ + crc.update(b); + } + + @Override + public void update ( long b) { + ByteBuffer v = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN); + v.putLong(b); + crc.update(v.array()); + } + + @Override + public void update ( byte[] b, int off, int len){ + crc.update(b, off, len); + } + + @Override + public long getValue () { + return crc.getValue(); + } + };*/ private ExecutorService executorService = null;//TODO: AAAAAAAAAAAAAAA MEMORY LEAK!!!!!!!!! public final AtomicBoolean globalShutdownBackupFlag = new AtomicBoolean(true); diff --git a/src/main/java/net/szum123321/textile_backup/core/create/BrokenFileHandler.java b/src/main/java/net/szum123321/textile_backup/core/create/BrokenFileHandler.java index 8e9b314..8e06585 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/BrokenFileHandler.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/BrokenFileHandler.java @@ -18,14 +18,12 @@ package net.szum123321.textile_backup.core.create; -import org.spongepowered.include.com.google.common.collect.Maps; - import java.nio.file.Path; import java.util.HashMap; import java.util.Map; public class BrokenFileHandler { - private final HashMap store = Maps.newHashMap(); + private final Map store = new HashMap<>(); public void handle(Path file, Exception e) { store.put(file, e); } public boolean valid() { return store.isEmpty(); } diff --git a/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java b/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java index 9f5071f..f51e033 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/ExecutableBackup.java @@ -21,7 +21,6 @@ import java.nio.file.Path; import java.time.LocalDateTime; import java.util.NoSuchElementException; import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; public record ExecutableBackup(@NotNull MinecraftServer server, ServerCommandSource commandSource, @@ -64,7 +63,7 @@ public record ExecutableBackup(@NotNull MinecraftServer server, log.info(builder.toString()); } @Override - public Void call() throws IOException, ExecutionException, InterruptedException { + public Void call() throws Exception { if (save) { //save the world log.sendInfoAL(this, "Saving server..."); server.saveAll(true, true, false); @@ -119,7 +118,7 @@ public record ExecutableBackup(@NotNull MinecraftServer server, } catch (Throwable e) { //ExecutorService swallows exception, so I need to catch everything - log.error("An exception occurred when trying to create new backup file!", e); + log.error("An exception occurred when trying to create a new backup file!", e); if (ConfigHelper.INSTANCE.get().integrityVerificationMode.isStrict()) { try { diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java b/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java index 8d67b83..c601cb8 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java @@ -20,7 +20,7 @@ package net.szum123321.textile_backup.core.digest; public interface Hash { - void update(int b) ; + void update(int b); void update(long b);