java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java
changeset 9 a2e91b20198b
parent 6 734f104f2869
child 10 ed2b6ebf138d
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java	Wed Dec 15 20:07:14 2010 +0100
     1.2 +++ b/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java	Wed Dec 15 22:38:03 2010 +0100
     1.3 @@ -1,5 +1,8 @@
     1.4  package cz.frantovo.rozsireneAtributy;
     1.5  
     1.6 +import java.nio.ByteBuffer;
     1.7 +import java.nio.charset.Charset;
     1.8 +
     1.9  public class Atribut {
    1.10  
    1.11  	private String klic;
    1.12 @@ -10,6 +13,11 @@
    1.13  		this.hodnota = hodnota;
    1.14  	}
    1.15  
    1.16 +	public Atribut(String klic, ByteBuffer hodnota) {
    1.17 +		this.klic = klic;
    1.18 +		setHodnota(hodnota);
    1.19 +	}
    1.20 +
    1.21  	public String getKlic() {
    1.22  		return klic;
    1.23  	}
    1.24 @@ -22,7 +30,24 @@
    1.25  		return hodnota;
    1.26  	}
    1.27  
    1.28 +	public final ByteBuffer getHodnotaBajty() {
    1.29 +		return zakóduj(getHodnota());
    1.30 +	}
    1.31 +
    1.32  	public void setHodnota(String hodnota) {
    1.33  		this.hodnota = hodnota;
    1.34  	}
    1.35 +
    1.36 +	public final void setHodnota(ByteBuffer hodnota) {
    1.37 +		setHodnota(dekóduj(hodnota));
    1.38 +	}
    1.39 +
    1.40 +	private static String dekóduj(ByteBuffer bajty) {
    1.41 +		bajty.flip();
    1.42 +		return Charset.defaultCharset().decode(bajty).toString();
    1.43 +	}
    1.44 +
    1.45 +	private static ByteBuffer zakóduj(String text) {
    1.46 +		return Charset.defaultCharset().encode(text);
    1.47 +	}
    1.48  }