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, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package cz.frantovo.rozsireneAtributy;
20 import java.nio.ByteBuffer;
21 import java.nio.charset.Charset;
23 public class Atribut {
26 private String hodnota;
28 public Atribut(String klíč, String hodnota) {
30 this.hodnota = hodnota;
33 public Atribut(String klíč, ByteBuffer hodnota) {
41 public String getKlíč() {
45 public void setKlíč(String klíč) {
50 * Název atributu musí být nenulový a mít nějakou délku, aby šel uložit
51 * TODO: další kontroly?
52 * @return jestli je platný
54 public boolean isPlatnýKlíč() {
55 return klíč != null && klíč.length() > 0;
59 * nulová hodnota → smazání atributu
60 * (ale může být prázdný řetězec)
61 * @return jestli je platná
63 public boolean isPlatnáHodnota() {
64 return hodnota != null;
67 public String getHodnota() {
71 public final ByteBuffer getHodnotaBajty() {
72 return zakóduj(getHodnota());
75 public void setHodnota(String hodnota) {
76 this.hodnota = hodnota;
79 public final void setHodnota(ByteBuffer hodnota) {
80 setHodnota(dekóduj(hodnota));
83 private static String dekóduj(ByteBuffer bajty) {
85 return Charset.defaultCharset().decode(bajty).toString();
88 private static ByteBuffer zakóduj(String text) {
92 return Charset.defaultCharset().encode(text);