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@4: public class PokusnýVýpis { 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@4: List jménaAtributů = pohled.list(); franta-hg@4: for (String jménoAtributu : jménaAtributů) { franta-hg@4: ByteBuffer bajty = ByteBuffer.allocate(pohled.size(jménoAtributu)); franta-hg@4: pohled.read(jménoAtributu, bajty); franta-hg@4: String hodnotaAtributu = dekóduj(bajty); franta-hg@4: System.out.println(jménoAtributu + " = " + hodnotaAtributu); franta-hg@2: } franta-hg@2: } franta-hg@2: franta-hg@4: private static String dekóduj(ByteBuffer bajty) { franta-hg@2: bajty.flip(); franta-hg@2: return Charset.defaultCharset().decode(bajty).toString(); franta-hg@2: } franta-hg@2: }