java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/Atribut.java
author František Kučera <franta-hg@frantovo.cz>
Wed Dec 15 22:38:03 2010 +0100 (2010-12-15)
changeset 9 a2e91b20198b
parent 6 734f104f2869
child 10 ed2b6ebf138d
permissions -rw-r--r--
Ukládání atributů (možnost změny stávajících).
     1 package cz.frantovo.rozsireneAtributy;
     2 
     3 import java.nio.ByteBuffer;
     4 import java.nio.charset.Charset;
     5 
     6 public class Atribut {
     7 
     8 	private String klic;
     9 	private String hodnota;
    10 
    11 	public Atribut(String klic, String hodnota) {
    12 		this.klic = klic;
    13 		this.hodnota = hodnota;
    14 	}
    15 
    16 	public Atribut(String klic, ByteBuffer hodnota) {
    17 		this.klic = klic;
    18 		setHodnota(hodnota);
    19 	}
    20 
    21 	public String getKlic() {
    22 		return klic;
    23 	}
    24 
    25 	public void setKlic(String klic) {
    26 		this.klic = klic;
    27 	}
    28 
    29 	public String getHodnota() {
    30 		return hodnota;
    31 	}
    32 
    33 	public final ByteBuffer getHodnotaBajty() {
    34 		return zakóduj(getHodnota());
    35 	}
    36 
    37 	public void setHodnota(String hodnota) {
    38 		this.hodnota = hodnota;
    39 	}
    40 
    41 	public final void setHodnota(ByteBuffer hodnota) {
    42 		setHodnota(dekóduj(hodnota));
    43 	}
    44 
    45 	private static String dekóduj(ByteBuffer bajty) {
    46 		bajty.flip();
    47 		return Charset.defaultCharset().decode(bajty).toString();
    48 	}
    49 
    50 	private static ByteBuffer zakóduj(String text) {
    51 		return Charset.defaultCharset().encode(text);
    52 	}
    53 }