2 * Rozšířené atributy – program na správu rozšířených atributů souborů
3 * Copyright © 2012 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package cz.frantovo.rozsireneAtributy;
19 import java.nio.ByteBuffer;
20 import java.nio.charset.Charset;
22 public class Atribut {
25 private String hodnota;
27 public Atribut(String klíč, String hodnota) {
29 this.hodnota = hodnota;
32 public Atribut(String klíč, ByteBuffer hodnota) {
40 public String getKlíč() {
44 public void setKlíč(String klíč) {
49 * Název atributu musí být nenulový a mít nějakou délku, aby šel uložit
50 * TODO: další kontroly?
51 * @return jestli je platný
53 public boolean isPlatnýKlíč() {
54 return klíč != null && klíč.length() > 0;
58 * nulová hodnota → smazání atributu
59 * (ale může být prázdný řetězec)
60 * @return jestli je platná
62 public boolean isPlatnáHodnota() {
63 return hodnota != null;
66 public String getHodnota() {
70 public final ByteBuffer getHodnotaBajty() {
71 return zakóduj(getHodnota());
74 public void setHodnota(String hodnota) {
75 this.hodnota = hodnota;
78 public final void setHodnota(ByteBuffer hodnota) {
79 setHodnota(dekóduj(hodnota));
82 private static String dekóduj(ByteBuffer bajty) {
84 return Charset.defaultCharset().decode(bajty).toString();
87 private static ByteBuffer zakóduj(String text) {
91 return Charset.defaultCharset().encode(text);