diff -r 734f104f2869 -r a2e91b20198b java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java Wed Dec 15 20:07:14 2010 +0100 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java Wed Dec 15 22:38:03 2010 +0100 @@ -1,5 +1,8 @@ package cz.frantovo.rozsireneAtributy; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + public class Atribut { private String klic; @@ -10,6 +13,11 @@ this.hodnota = hodnota; } + public Atribut(String klic, ByteBuffer hodnota) { + this.klic = klic; + setHodnota(hodnota); + } + public String getKlic() { return klic; } @@ -22,7 +30,24 @@ return hodnota; } + public final ByteBuffer getHodnotaBajty() { + return zakóduj(getHodnota()); + } + public void setHodnota(String hodnota) { this.hodnota = hodnota; } + + public final void setHodnota(ByteBuffer hodnota) { + setHodnota(dekóduj(hodnota)); + } + + private static String dekóduj(ByteBuffer bajty) { + bajty.flip(); + return Charset.defaultCharset().decode(bajty).toString(); + } + + private static ByteBuffer zakóduj(String text) { + return Charset.defaultCharset().encode(text); + } }