From 2e221d98dc41d2b9820de781eba4a9606f0c09b8 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 2 Apr 2017 00:33:40 +0800 Subject: [PATCH] Refactor MetaAttributeView --- source/net/filebot/MetaAttributeView.java | 32 +++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/source/net/filebot/MetaAttributeView.java b/source/net/filebot/MetaAttributeView.java index 7fff35fa..78c16219 100644 --- a/source/net/filebot/MetaAttributeView.java +++ b/source/net/filebot/MetaAttributeView.java @@ -6,7 +6,6 @@ import static net.filebot.Logging.*; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.UserDefinedFileAttributeView; @@ -21,8 +20,7 @@ import net.filebot.platform.mac.MacXattrView; public class MetaAttributeView extends AbstractMap { - private Object xattr; - private Charset encoding = UTF_8; + private final Object xattr; public MetaAttributeView(File file) throws IOException { // resolve symlinks @@ -56,7 +54,7 @@ public class MetaAttributeView extends AbstractMap { attributeView.read(key, buffer); buffer.flip(); - return encoding.decode(buffer).toString(); + return UTF_8.decode(buffer).toString(); } else { return null; // attribute does not exist } @@ -81,7 +79,7 @@ public class MetaAttributeView extends AbstractMap { if (value == null || value.isEmpty()) { attributeView.delete(key); } else { - attributeView.write(key, encoding.encode(value)); + attributeView.write(key, UTF_8.encode(value)); } } @@ -100,6 +98,17 @@ public class MetaAttributeView extends AbstractMap { return null; // since we don't know the old value } + @Override + public void clear() { + try { + for (String key : list()) { + put(key, null); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + public List list() throws IOException { if (xattr instanceof UserDefinedFileAttributeView) { UserDefinedFileAttributeView attributeView = (UserDefinedFileAttributeView) xattr; @@ -118,7 +127,7 @@ public class MetaAttributeView extends AbstractMap { public Set> entrySet() { try { Set> entries = new LinkedHashSet>(); - for (String name : this.list()) { + for (String name : list()) { entries.add(new AttributeEntry(name)); } return entries; @@ -127,17 +136,6 @@ public class MetaAttributeView extends AbstractMap { } } - @Override - public void clear() { - try { - for (String key : this.list()) { - this.put(key, null); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - private class AttributeEntry implements Entry { private final String name;