Minor optimizations
This commit is contained in:
parent
838fd5b155
commit
09ff31d88e
|
@ -14,7 +14,7 @@
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/junit.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/junit.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/miglayout-core.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/miglayout-core.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/miglayout-swing.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/miglayout-swing.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/rsyntaxtextarea.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/rsyntaxtextarea.jar" sourcepath="lib/ivy/source/rsyntaxtextarea.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/xz.jar" sourcepath="lib/ivy/source/xz.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/xz.jar" sourcepath="lib/ivy/source/xz.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/slf4j-api.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/slf4j-api.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/commons-io.jar" sourcepath="lib/ivy/source/commons-io.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/commons-io.jar" sourcepath="lib/ivy/source/commons-io.jar"/>
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.text.Normalizer;
|
import java.text.Normalizer;
|
||||||
import java.text.Normalizer.Form;
|
import java.text.Normalizer.Form;
|
||||||
|
@ -36,6 +37,7 @@ import java.util.function.IntFunction;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.tukaani.xz.XZInputStream;
|
import org.tukaani.xz.XZInputStream;
|
||||||
|
|
||||||
|
@ -493,8 +495,9 @@ public class ReleaseInfo {
|
||||||
byte[] bytes = cache.bytes(name, n -> new URL(getProperty(n)), XZInputStream::new).expire(refreshDuration.optional().orElse(expirationTime)).get();
|
byte[] bytes = cache.bytes(name, n -> new URL(getProperty(n)), XZInputStream::new).expire(refreshDuration.optional().orElse(expirationTime)).get();
|
||||||
|
|
||||||
// all data files are UTF-8 encoded XZ compressed text files
|
// all data files are UTF-8 encoded XZ compressed text files
|
||||||
String text = new String(bytes, UTF_8);
|
Stream<String> lines = NEWLINE.splitAsStream(UTF_8.decode(ByteBuffer.wrap(bytes)));
|
||||||
return NEWLINE.splitAsStream(text).filter(s -> s.length() > 0).map(parse).filter(Objects::nonNull).toArray(generator);
|
|
||||||
|
return lines.filter(s -> s.length() > 0).map(parse).filter(Objects::nonNull).toArray(generator);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package net.filebot.ui.rename;
|
package net.filebot.ui.rename;
|
||||||
|
|
||||||
import static java.util.Arrays.*;
|
|
||||||
import static java.util.stream.Collectors.*;
|
import static java.util.stream.Collectors.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
import static net.filebot.MediaTypes.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
import static net.filebot.util.RegularExpressions.*;
|
|
||||||
|
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -66,8 +64,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||||
// load file paths from text files
|
// load file paths from text files
|
||||||
if (recursive && LIST_FILES.accept(f)) {
|
if (recursive && LIST_FILES.accept(f)) {
|
||||||
try {
|
try {
|
||||||
String[] lines = NEWLINE.split(readTextFile(f));
|
List<File> paths = readLines(f).stream().filter(s -> s.length() > 0).map(path -> {
|
||||||
List<File> paths = stream(lines).filter(s -> s.length() > 0).map(path -> {
|
|
||||||
try {
|
try {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
return file.isAbsolute() && file.exists() ? file : null;
|
return file.isAbsolute() && file.exists() ? file : null;
|
||||||
|
|
|
@ -49,11 +49,11 @@ public class FileSet extends AbstractSet<Path> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean add(File e) {
|
public boolean add(File e) {
|
||||||
return add(getPath(e));
|
return add(e.toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean add(String e) {
|
public boolean add(String e) {
|
||||||
return add(getPath(e));
|
return add(Paths.get(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean contains(Path e, int depth) {
|
private boolean contains(Path e, int depth) {
|
||||||
|
@ -160,7 +160,7 @@ public class FileSet extends AbstractSet<Path> {
|
||||||
public void load(File f) throws IOException {
|
public void load(File f) throws IOException {
|
||||||
for (String path : readLines(f)) {
|
for (String path : readLines(f)) {
|
||||||
try {
|
try {
|
||||||
add(Paths.get(path));
|
add(path);
|
||||||
} catch (InvalidPathException e) {
|
} catch (InvalidPathException e) {
|
||||||
debug.warning(e::toString);
|
debug.warning(e::toString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collector;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
@ -186,22 +187,26 @@ public final class FileUtilities {
|
||||||
private static final String WIN_THUMBNAIL_STORE = "Thumbs.db";
|
private static final String WIN_THUMBNAIL_STORE = "Thumbs.db";
|
||||||
private static final String MAC_THUMBNAIL_STORE = ".DS_Store";
|
private static final String MAC_THUMBNAIL_STORE = ".DS_Store";
|
||||||
|
|
||||||
public static boolean isThumbnailStore(File f) {
|
public static boolean isThumbnailStore(File file) {
|
||||||
return MAC_THUMBNAIL_STORE.equals(f.getName()) || WIN_THUMBNAIL_STORE.equalsIgnoreCase(f.getName());
|
return MAC_THUMBNAIL_STORE.equals(file.getName()) || WIN_THUMBNAIL_STORE.equalsIgnoreCase(file.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] readFile(File source) throws IOException {
|
public static byte[] readFile(File file) throws IOException {
|
||||||
return Files.readAllBytes(source.toPath());
|
return Files.readAllBytes(file.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <R, A> R readLines(File file, Collector<? super String, A, R> collector) throws IOException {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new UnicodeReader(new ByteArrayInputStream(readFile(file)), false, UTF_8))) {
|
||||||
|
return reader.lines().collect(collector);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> readLines(File file) throws IOException {
|
public static List<String> readLines(File file) throws IOException {
|
||||||
try (BufferedReader reader = new BufferedReader(new UnicodeReader(new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE), false, UTF_8), BUFFER_SIZE)) {
|
return readLines(file, toList());
|
||||||
return reader.lines().collect(toList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String readTextFile(File file) throws IOException {
|
public static String readTextFile(File file) throws IOException {
|
||||||
return String.join(System.lineSeparator(), readLines(file));
|
return readLines(file, joining(System.lineSeparator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File writeFile(ByteBuffer data, File destination) throws IOException {
|
public static File writeFile(ByteBuffer data, File destination) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue