author | František Kučera <franta-hg@frantovo.cz> |
Wed Dec 15 18:53:00 2010 +0100 (2010-12-15) | |
changeset 4 | 8183e063968c |
parent 2 | java/rozsirene-atributy/src/cz/frantovo/rozsireneAtributy/PokusnyVypis.java@7cafdce717dd |
permissions | -rw-r--r-- |
franta-hg@2 | 1 |
package cz.frantovo.rozsireneAtributy; |
franta-hg@2 | 2 |
|
franta-hg@2 | 3 |
import java.io.File; |
franta-hg@2 | 4 |
import java.io.IOException; |
franta-hg@2 | 5 |
import java.nio.ByteBuffer; |
franta-hg@2 | 6 |
import java.nio.charset.Charset; |
franta-hg@2 | 7 |
import java.nio.file.Path; |
franta-hg@2 | 8 |
import java.nio.file.attribute.UserDefinedFileAttributeView; |
franta-hg@2 | 9 |
import java.util.List; |
franta-hg@2 | 10 |
|
franta-hg@2 | 11 |
/** |
franta-hg@2 | 12 |
* http://freedesktop.org/wiki/CommonExtendedAttributes |
franta-hg@2 | 13 |
* http://download.oracle.com/javase/tutorial/essential/io/fileAttr.html#user |
franta-hg@2 | 14 |
* 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 | 15 |
* |
franta-hg@2 | 16 |
* $ setfattr -n user.fiki.pozdrav -v 'Dobrý den!' pokus.txt |
franta-hg@2 | 17 |
* |
franta-hg@2 | 18 |
* @author fiki |
franta-hg@2 | 19 |
*/ |
franta-hg@4 | 20 |
public class PokusnýVýpis { |
franta-hg@2 | 21 |
|
franta-hg@2 | 22 |
/** |
franta-hg@2 | 23 |
* Vypíše rozšířené atributy souboru. |
franta-hg@2 | 24 |
* @param args pole s jedním prvkem – názvem souboru |
franta-hg@2 | 25 |
* @throws IOException |
franta-hg@2 | 26 |
*/ |
franta-hg@2 | 27 |
public static void main(String[] args) throws IOException { |
franta-hg@2 | 28 |
File soubor = new File(args[0]); |
franta-hg@2 | 29 |
Path cesta = soubor.toPath(); |
franta-hg@2 | 30 |
UserDefinedFileAttributeView pohled = cesta.getFileAttributeView(UserDefinedFileAttributeView.class); |
franta-hg@4 | 31 |
List<String> jménaAtributů = pohled.list(); |
franta-hg@4 | 32 |
for (String jménoAtributu : jménaAtributů) { |
franta-hg@4 | 33 |
ByteBuffer bajty = ByteBuffer.allocate(pohled.size(jménoAtributu)); |
franta-hg@4 | 34 |
pohled.read(jménoAtributu, bajty); |
franta-hg@4 | 35 |
String hodnotaAtributu = dekóduj(bajty); |
franta-hg@4 | 36 |
System.out.println(jménoAtributu + " = " + hodnotaAtributu); |
franta-hg@2 | 37 |
} |
franta-hg@2 | 38 |
} |
franta-hg@2 | 39 |
|
franta-hg@4 | 40 |
private static String dekóduj(ByteBuffer bajty) { |
franta-hg@2 | 41 |
bajty.flip(); |
franta-hg@2 | 42 |
return Charset.defaultCharset().decode(bajty).toString(); |
franta-hg@2 | 43 |
} |
franta-hg@2 | 44 |
} |