mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-01-09 09:17:39 +00:00
Revert portion of "Minor cleanup" to fix history bugs
This commit is contained in:
parent
238c56a3c6
commit
33c3cb2f33
@ -0,0 +1,33 @@
|
|||||||
|
package com.boydti.fawe.object;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
public abstract class RunnableVal2<T, U> implements Runnable, BiConsumer<T, U> {
|
||||||
|
public T value1;
|
||||||
|
public U value2;
|
||||||
|
|
||||||
|
public RunnableVal2() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RunnableVal2(T value1, U value2) {
|
||||||
|
this.value1 = value1;
|
||||||
|
this.value2 = value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
run(this.value1, this.value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run(T value1, U value2);
|
||||||
|
|
||||||
|
public RunnableVal2<T, U> runAndGet(T value1, U value2) {
|
||||||
|
run(value1, value2);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(T t, U u) {
|
||||||
|
run(t, u);
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,7 @@ package com.boydti.fawe.util;
|
|||||||
|
|
||||||
import com.boydti.fawe.Fawe;
|
import com.boydti.fawe.Fawe;
|
||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
import com.boydti.fawe.object.FaweInputStream;
|
import com.boydti.fawe.object.*;
|
||||||
import com.boydti.fawe.object.FaweOutputStream;
|
|
||||||
import com.boydti.fawe.object.RegionWrapper;
|
|
||||||
import com.boydti.fawe.object.RunnableVal;
|
|
||||||
import com.boydti.fawe.object.changeset.FaweStreamChangeSet;
|
import com.boydti.fawe.object.changeset.FaweStreamChangeSet;
|
||||||
import com.boydti.fawe.object.io.AbstractDelegateOutputStream;
|
import com.boydti.fawe.object.io.AbstractDelegateOutputStream;
|
||||||
import com.github.luben.zstd.ZstdInputStream;
|
import com.github.luben.zstd.ZstdInputStream;
|
||||||
@ -40,6 +37,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
@ -71,22 +69,22 @@ public class MainUtil {
|
|||||||
|
|
||||||
public static long getTotalSize(Path path) {
|
public static long getTotalSize(Path path) {
|
||||||
final AtomicLong size = new AtomicLong(0);
|
final AtomicLong size = new AtomicLong(0);
|
||||||
traverse(path, new RunnableVal<BasicFileAttributes>() {
|
traverse(path, new RunnableVal2<Path, BasicFileAttributes>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(BasicFileAttributes attrs) {
|
public void run(Path path, BasicFileAttributes attrs) {
|
||||||
size.addAndGet(attrs.size());
|
size.addAndGet(attrs.size());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return size.get();
|
return size.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void traverse(Path path, final Consumer<BasicFileAttributes> onEach) {
|
public static void traverse(Path path, final BiConsumer<Path, BasicFileAttributes> onEach) {
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult
|
public FileVisitResult
|
||||||
visitFile(Path file, BasicFileAttributes attrs) {
|
visitFile(Path file, BasicFileAttributes attrs) {
|
||||||
onEach.accept(attrs);
|
onEach.accept(file, attrs);
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +126,7 @@ public class MainUtil {
|
|||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forEachFile(Path path, final RunnableVal<BasicFileAttributes> onEach, Comparator<File> comparator) {
|
public static void forEachFile(Path path, final RunnableVal2<Path, BasicFileAttributes> onEach, Comparator<File> comparator) {
|
||||||
File dir = path.toFile();
|
File dir = path.toFile();
|
||||||
if (!dir.exists()) return;
|
if (!dir.exists()) return;
|
||||||
File[] files = path.toFile().listFiles();
|
File[] files = path.toFile().listFiles();
|
||||||
@ -137,7 +135,7 @@ public class MainUtil {
|
|||||||
Path filePath = file.toPath();
|
Path filePath = file.toPath();
|
||||||
try {
|
try {
|
||||||
BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class);
|
BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class);
|
||||||
onEach.run(attr);
|
onEach.run(file.toPath(), attr);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user