franta-hg@2: package cz.frantovo.rozsireneAtributy; franta-hg@2: franta-hg@2: import java.io.File; franta-hg@2: import java.io.IOException; franta-hg@2: import java.nio.ByteBuffer; franta-hg@2: import java.nio.charset.Charset; franta-hg@2: import java.nio.file.Path; franta-hg@2: import java.nio.file.attribute.UserDefinedFileAttributeView; franta-hg@2: import java.util.List; franta-hg@2: franta-hg@2: /** franta-hg@2: * http://freedesktop.org/wiki/CommonExtendedAttributes franta-hg@2: * http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user franta-hg@2: * http://today.java.net/pub/a/today/2008/07/03/jsr-203-new-file-apis.html#so-what-is-a-path-really franta-hg@2: * franta-hg@2: * $ setfattr -n user.fiki.pozdrav -v 'Dobrý den!' pokus.txt franta-hg@2: * franta-hg@2: * @author fiki franta-hg@2: */ franta-hg@2: public class PokusnyVypis { franta-hg@2: franta-hg@2: /** franta-hg@2: * Vypíše rozšířené atributy souboru. franta-hg@2: * @param args pole s jedním prvkem – názvem souboru franta-hg@2: * @throws IOException franta-hg@2: */ franta-hg@2: public static void main(String[] args) throws IOException { franta-hg@2: File soubor = new File(args[0]); franta-hg@2: Path cesta = soubor.toPath(); franta-hg@2: UserDefinedFileAttributeView pohled = cesta.getFileAttributeView(UserDefinedFileAttributeView.class); franta-hg@2: List jmenaAtributu = pohled.list(); franta-hg@2: for (String jmenoAtributu : jmenaAtributu) { franta-hg@2: ByteBuffer bajty = ByteBuffer.allocate(pohled.size(jmenoAtributu)); franta-hg@2: pohled.read(jmenoAtributu, bajty); franta-hg@2: String hodnotaAtributu = dekoduj(bajty); franta-hg@2: System.out.println(jmenoAtributu + " = " + hodnotaAtributu); franta-hg@2: } franta-hg@2: } franta-hg@2: franta-hg@2: private static String dekoduj(ByteBuffer bajty) { franta-hg@2: bajty.flip(); franta-hg@2: return Charset.defaultCharset().decode(bajty).toString(); franta-hg@2: } franta-hg@2: }