* refactoring

This commit is contained in:
Reinhard Pointner 2014-03-26 16:39:21 +00:00
parent 8b2e38a149
commit 91f37a5d20
4 changed files with 52 additions and 61 deletions

View File

@ -1359,6 +1359,21 @@ public class MediaDetection {
}
};
public static Object loadMetaInfo(File file) {
if (useExtendedFileAttributes()) {
try {
MetaAttributes xattr = new MetaAttributes(file);
Object meta = xattr.getObject();
if (meta instanceof Episode || meta instanceof Movie) {
return meta;
}
} catch (Throwable e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Unable to read xattr: " + e.getMessage());
}
}
return null;
}
public static void storeMetaInfo(File file, Object model, String original, boolean useExtendedFileAttributes, boolean useCreationDate) {
// only for Episode / Movie objects
if ((useExtendedFileAttributes || useCreationDate) && (model instanceof Episode || model instanceof Movie) && file.isFile()) {
@ -1387,7 +1402,9 @@ public class MediaDetection {
// store original name and model as xattr
if (useExtendedFileAttributes) {
try {
xattr.setObject(model);
if (model instanceof Episode || model instanceof Movie) {
xattr.setObject(model);
}
if (xattr.getOriginalName() == null && original != null) {
xattr.setOriginalName(original);
}

View File

@ -98,7 +98,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
}
}
model.addAll(FastFile.foreach(entries));
model.addAll(FastFile.get(entries));
}
@Override

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.ui.rename;
import static java.awt.datatransfer.DataFlavor.*;
import static net.sourceforge.filebot.hash.VerificationUtilities.*;
import static net.sourceforge.filebot.ui.transfer.FileTransferable.*;
@ -26,37 +24,31 @@ import net.sourceforge.filebot.vfs.SimpleFileInfo;
import net.sourceforge.filebot.web.Episode;
import net.sourceforge.tuned.FastFile;
class NamesListTransferablePolicy extends FileTransferablePolicy {
private static final DataFlavor episodeArrayFlavor = ArrayTransferable.flavor(Episode.class);
private final List<Object> model;
public NamesListTransferablePolicy(List<Object> model) {
this.model = model;
}
@Override
protected void clear() {
model.clear();
}
@Override
public boolean accept(Transferable tr) throws Exception {
return tr.isDataFlavorSupported(stringFlavor) || hasFileListFlavor(tr);
}
@Override
protected boolean accept(List<File> files) {
return true;
}
@Override
public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
if (action == TransferAction.PUT) {
@ -75,15 +67,12 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
}
}
protected void load(String string) {
List<String> values = new ArrayList<String>();
Scanner scanner = new Scanner(string);
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (line.length() > 0) {
values.add(line);
}
@ -92,7 +81,6 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
model.addAll(values);
}
@Override
protected void load(List<File> files) throws IOException {
List<Object> values = new ArrayList<Object>();
@ -108,13 +96,12 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
loadTorrentFiles(files, values);
} else {
// load all files from the given folders recursively up do a depth of 5
values.addAll(FastFile.foreach(flatten(files, 5, false)));
values.addAll(FastFile.get(flatten(files, 5, false)));
}
model.addAll(values);
}
protected void loadListFiles(List<File> files, List<Object> values) throws IOException {
for (File file : files) {
// don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019)
@ -132,7 +119,6 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
}
}
protected void loadVerificationFiles(List<File> files, List<Object> values) throws IOException {
for (File verificationFile : files) {
HashType type = getHashType(verificationFile);
@ -154,7 +140,6 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
}
}
protected void loadTorrentFiles(List<File> files, List<Object> values) throws IOException {
for (File file : files) {
Torrent torrent = new Torrent(file);
@ -165,7 +150,6 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
}
}
@Override
public String getFileFilterDescription() {
return "text files, verification files, torrent files";

View File

@ -1,48 +1,39 @@
package net.sourceforge.tuned;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class FastFile extends File {
private Long length;
private Boolean isDirectory;
private Boolean isFile;
public FastFile(String path) {
super(path);
}
public FastFile(File parent, String child) {
super(parent, child);
}
@Override
public long length() {
return length != null ? length : (length = super.length());
}
@Override
public boolean isDirectory() {
return isDirectory != null ? isDirectory : (isDirectory = super.isDirectory());
}
@Override
public boolean isFile() {
return isFile != null ? isFile : (isFile = super.isFile());
}
@Override
public File[] listFiles() {
String[] names = list();
@ -56,13 +47,11 @@ public class FastFile extends File {
return files;
}
public static List<FastFile> foreach(File... files) {
return foreach(Arrays.asList(files));
public static FastFile get(File file) {
return new FastFile(file.getPath());
}
public static List<FastFile> foreach(final List<File> files) {
public static List<FastFile> get(Collection<File> files) {
List<FastFile> result = new ArrayList<FastFile>(files.size());
for (File file : files) {
@ -71,4 +60,5 @@ public class FastFile extends File {
return result;
}
}