diff -r e62a3e498212 -r 02739f60b1ec java/alt2xml-in-fs/src/cz/frantovo/alt2xml/in/fs/ExtendedAttribute.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/alt2xml-in-fs/src/cz/frantovo/alt2xml/in/fs/ExtendedAttribute.java Wed Oct 29 02:03:14 2014 +0100 @@ -0,0 +1,77 @@ +/** + * Alt2XML + * Copyright © 2014 František Kučera (frantovo.cz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package cz.frantovo.alt2xml.in.fs; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +public class ExtendedAttribute { + + private String key; + private String value; + + public ExtendedAttribute(String key, String value) { + this.key = key; + this.value = value; + } + + public ExtendedAttribute(String key, ByteBuffer value) { + this.key = key; + setValue(value); + } + + public ExtendedAttribute() { + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public final ByteBuffer getValueBytes() { + return encode(getValue()); + } + + public void setValue(String value) { + this.value = value; + } + + public final void setValue(ByteBuffer value) { + setValue(decode(value)); + } + + private static String decode(ByteBuffer bytes) { + bytes.flip(); + return Charset.defaultCharset().decode(bytes).toString(); + } + + private static ByteBuffer encode(String text) { + if (text == null) { + return null; + } else { + return Charset.defaultCharset().encode(text); + } + } +}