1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/PokusnyVypis.java Wed Dec 15 18:17:15 2010 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,44 +0,0 @@
1.4 -package cz.frantovo.rozsireneAtributy;
1.5 -
1.6 -import java.io.File;
1.7 -import java.io.IOException;
1.8 -import java.nio.ByteBuffer;
1.9 -import java.nio.charset.Charset;
1.10 -import java.nio.file.Path;
1.11 -import java.nio.file.attribute.UserDefinedFileAttributeView;
1.12 -import java.util.List;
1.13 -
1.14 -/**
1.15 - * http://freedesktop.org/wiki/CommonExtendedAttributes
1.16 - * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
1.17 - * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
1.18 - *
1.19 - * $ setfattr -n user.fiki.pozdrav -v 'Dobrý den!' pokus.txt
1.20 - *
1.21 - * @author fiki
1.22 - */
1.23 -public class PokusnyVypis {
1.24 -
1.25 - /**
1.26 - * Vypíše rozšířené atributy souboru.
1.27 - * @param args pole s jedním prvkem – názvem souboru
1.28 - * @throws IOException
1.29 - */
1.30 - public static void main(String[] args) throws IOException {
1.31 - File soubor = new File(args[0]);
1.32 - Path cesta = soubor.toPath();
1.33 - UserDefinedFileAttributeView pohled = cesta.getFileAttributeView(UserDefinedFileAttributeView.class);
1.34 - List<String> jmenaAtributu = pohled.list();
1.35 - for (String jmenoAtributu : jmenaAtributu) {
1.36 - ByteBuffer bajty = ByteBuffer.allocate(pohled.size(jmenoAtributu));
1.37 - pohled.read(jmenoAtributu, bajty);
1.38 - String hodnotaAtributu = dekoduj(bajty);
1.39 - System.out.println(jmenoAtributu + " = " + hodnotaAtributu);
1.40 - }
1.41 - }
1.42 -
1.43 - private static String dekoduj(ByteBuffer bajty) {
1.44 - bajty.flip();
1.45 - return Charset.defaultCharset().decode(bajty).toString();
1.46 - }
1.47 -}