osx - How to store a hash in extended file attributes on OS X with Java? -


preface working on platform in-depended media database written in java media files identified file hash. user shall able move files around, not want rely on file path. once imported, store path , hash in database. developed fast file-hash-id algorithm based on tradeoff between accuracy , performance, fast not fast enough. :)

in order update , import mediafiles, need (re)create file hashes of files in library. idea calculate hash once , store in files metadata (extended attributes) boost performance on filesystems support extended file attributes. (ntfs, hfs+, ext3...) implemented it, , can find current source here: archimedesj.io.metadata

attempts @ first glance, java 1.7 offers userdefinedfileattributeview nice way handle metadata. platforms works. sadly, userdefinedfileattributeview not work on hfs+. albeit, not understand why hfs+ filesystem not supported - 1 of leading formats metadata? (see related question - which not provide solution)

how store extended file attributes on os x java? in oder come java limitation, decided use xattr commandline tool present on osx , use javas process handling read output it. my implementation works, slow. (recalculation of file hash faster, how ironic! i testing on mac bookpro retina, ssd.)

it turned out, xattr tool works quite slow. (writing damn slow, more importantly reading attribute slow) prove not java issue tool itself, have created simple bash script use xattr tool on several files have custom attribute:

files=/users/isnull/pictures/ f in $files   xattr -p vidada.hash $f done 

if run it, lines appear "fast" after each other, expect show me output within milliseconds. little delay visible , guess tool not fast. using in java gives me additional overhead of creating process, parsing output makes bit slower.

is there better way access extended attributes on hfs+ java? fast way work extended attributes on os x java?

os x's /usr/bin/xattr rather slow because it's implemented python script. c api setting extended attributes setxattr(2). here's example:

if(setxattr("/path/to/file",             attribute_name,             (void *)attribute_data,             attribute_size,             0,             xattr_nofollow) != 0) {   /* error occurred, see errno */ } 

you can create jni wrapper access function java; might want getxattr(2), listxattr(2), , removexattr(2), depending on else app needs do.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -