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 PokusnýVýpis {
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> jménaAtributů = pohled.list();
32 for (String jménoAtributu : jménaAtributů) {
33 ByteBuffer bajty = ByteBuffer.allocate(pohled.size(jménoAtributu));
34 pohled.read(jménoAtributu, bajty);
35 String hodnotaAtributu = dekóduj(bajty);
36 System.out.println(jménoAtributu + " = " + hodnotaAtributu);
40 private static String dekóduj(ByteBuffer bajty) {
42 return Charset.defaultCharset().decode(bajty).toString();