Refactor MetaAttributeView

This commit is contained in:
Reinhard Pointner 2016-08-10 00:49:17 +08:00
parent 9705602e43
commit 38bc994638
1 changed files with 9 additions and 12 deletions

View File

@ -17,15 +17,14 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import net.filebot.mac.xattr.XAttrUtil;
import com.sun.jna.Platform; import com.sun.jna.Platform;
import net.filebot.mac.xattr.XAttrUtil;
public class MetaAttributeView extends AbstractMap<String, String> { public class MetaAttributeView extends AbstractMap<String, String> {
// UserDefinedFileAttributeView (for Windows and Linux) OR our own xattr.h JNA wrapper via MacXattrView (for Mac) because UserDefinedFileAttributeView is not supported (Oracle Java 7/8)
private Object xattr; private Object xattr;
private Charset encoding; private Charset encoding = UTF_8;
public MetaAttributeView(File file) throws IOException { public MetaAttributeView(File file) throws IOException {
Path path = file.getCanonicalFile().toPath(); Path path = file.getCanonicalFile().toPath();
@ -37,17 +36,15 @@ public class MetaAttributeView extends AbstractMap<String, String> {
path = link; path = link;
} }
xattr = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class); // UserDefinedFileAttributeView (for Windows and Linux) OR our own xattr.h JNA wrapper via MacXattrView (for Mac) because UserDefinedFileAttributeView is not supported (Oracle Java 7/8)
if (xattr == null) {
if (Platform.isMac()) { if (Platform.isMac()) {
xattr = new MacXattrView(path); xattr = new MacXattrView(path);
} else { } else {
xattr = Files.getFileAttributeView(path, UserDefinedFileAttributeView.class);
if (xattr == null) {
throw new IOException("UserDefinedFileAttributeView is not supported"); throw new IOException("UserDefinedFileAttributeView is not supported");
} }
} else {
// UserDefinedFileAttributeView
this.encoding = UTF_8;
} }
} }