Pokusný výpis rozšířených atributů souboru.
Příklad použití:
$ setfattr -n "user.pokus" -v "ahoj" licence/licence.txt
$ setfattr -n "user.čeština" -v "fpohodě – +ěšččíáýéá=" licence/licence.txt
$ /opt/jdk1.7.0/bin/java -jar java/rozsirene-atributy/dist/rozsirene-atributy.jar licence/licence.txt
1 package cz.frantovo.rozsireneAtributy;
4 import java.io.IOException;
5 import java.nio.ByteBuffer;
6 import java.nio.charset.Charset;
7 import java.nio.file.Path;
8 import java.nio.file.attribute.UserDefinedFileAttributeView;
12 * http://freedesktop.org/wiki/CommonExtendedAttributes
13 * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user
14 * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really
16 * $ setfattr -n user.fiki.pozdrav -v 'Dobrý den!' pokus.txt
20 public class PokusnyVypis {
23 * Vypíše rozšířené atributy souboru.
24 * @param args pole s jedním prvkem – názvem souboru
27 public static void main(String[] args) throws IOException {
28 File soubor = new File(args[0]);
29 Path cesta = soubor.toPath();
30 UserDefinedFileAttributeView pohled = cesta.getFileAttributeView(UserDefinedFileAttributeView.class);
31 List<String> jmenaAtributu = pohled.list();
32 for (String jmenoAtributu : jmenaAtributu) {
33 ByteBuffer bajty = ByteBuffer.allocate(pohled.size(jmenoAtributu));
34 pohled.read(jmenoAtributu, bajty);
35 String hodnotaAtributu = dekoduj(bajty);
36 System.out.println(jmenoAtributu + " = " + hodnotaAtributu);
40 private static String dekoduj(ByteBuffer bajty) {
42 return Charset.defaultCharset().decode(bajty).toString();