{"id":21884023,"url":"https://github.com/leiless/xattr4j","last_synced_at":"2026-05-19T09:33:11.216Z","repository":{"id":140255225,"uuid":"175015141","full_name":"leiless/xattr4j","owner":"leiless","description":"macOS native xattr syscall wrappers(JNI) for Java","archived":false,"fork":false,"pushed_at":"2019-06-20T14:03:10.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-15T00:39:53.065Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leiless.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-11T14:15:53.000Z","updated_at":"2019-06-20T14:03:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef64f5c2-5f9a-4be0-a8ef-9178dbf0d587","html_url":"https://github.com/leiless/xattr4j","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leiless%2Fxattr4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leiless%2Fxattr4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leiless%2Fxattr4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leiless%2Fxattr4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leiless","download_url":"https://codeload.github.com/leiless/xattr4j/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244892316,"owners_count":20527426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T10:11:54.730Z","updated_at":"2026-05-19T09:33:11.182Z","avatar_url":"https://github.com/leiless.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xattr4j - macOS native xattr syscall wrappers(JNI) for Java\n\nxattr4j is a JNI wrapper which enables Java to access/modify extended attributes over native syscalls.\n\n# Availability\n\nCurrently, only macOS is guaranteed to be supported(Other Unix-like systems which have `\u003csys/xattr.h\u003e` header may require slight changes).\n\n\u003e [[sic]](https://github.com/IsNull/xattrj#scope) On Windows and Linux you can access the xattr by using Javas UserDefinedFileAttributeView which seems to work nativly too. (UserDefinedFileAttributeView is not supported on HFS+ with Java 7 or anything before.)\n\n# Build\n\nThis project use `Makefile` for build, the following targets are avaiable:\n\n* `javac` - Generate JNI C header and compile Java classes\n\n* `jni-debug` - Build JNI C code with debug info\n\n* `jni-release` - Build JNI C code for release\n\n* `jar-debug` - Build `jni-debug` and pack into jar\n\n* `jar-release` - Build `jni-release` and pack into jar\n\n* `release` - Alias of `jar-release`\n\nDefault target is `jar-debug`.\n\n\u003cbr\u003e\n\nYou can override the following variables before make:\n\n* `JAVA_VERSION` - JDK version, format 1.x\n\n* `JAVA_HOME` - JDK home path\n\n* `CC` - Which compiler\n\n* `ARCHS` - Build architecture(s)\n\n* `CPPFLAGS` - C preprocessor flags\n\n* `CFLAGS` - C flags\n\n* (macOS) `MACOSX_VERSION_MIN` - Minimal macOS version supported(default 10.6)\n\n# Install\n\nPlease specify `PREFIX` variable before make, default installation is `~/Library/Java/Extensions`.\n\n```shell\n# Install xattr4j to default location\nmake install\n# Uninstall xatt4j from default localtion\nmake uninstall\n\n# Install xattr4j to given localtion\nsudo PREFIX=/Library/Java/Extensions make install\n# Uninstall xatt4j from given localtion\nsudo PREFIX=/Library/Java/Extensions make uninstall\n```\n\n# Use of `xattr4j`\n\n### Get an extended attribute value\n\n```java\nXAttr4J.getxattr(path, xattr_name, options);\nXAttr4J.fgetxattr(fd, xattr_name, options);\n```\n\n### Set an extended attribute value\n\n```java\nXAttr4J.setxattr(path, xattr_name, xattr_value, options);\nXAttr4J.fsetxattr(fd, xattr_name, xattr_value, options);\n```\n\n### Remove an extended attribute value\n\n```java\n// Remove a xattr(explicitly provide the is_force flag)\nXAttr4J.removexattr(path, xattr_name, options, is_force);\nXAttr4J.fremovexattr(fd, xattr_name, options, is_force);\n\n// Ditto.(is_force = false)\nXAttr4J.removexattr(path, xattr_name, options);\nXAttr4J.fremovexattr(fd, xattr_name, options);\n```\n\n### List extended attribute names\n\n```java\nXAttr4J.listxattr(path, options);\nXAttr4J.flistxattr(fd, options);\n```\n\n### Get size of an extended attribute value\n\n```java\nXAttr4J.sizexattr(path, xattr_name, options);\nXAttr4J.fsizexattr(fd, xattr_name, options);\n```\n\n### Check existence of an extended attribute\n\n```java\nXAttr4J.existxattr(path, xattr_name, options);\nXAttr4J.fexistxattr(fd, xattr_name, options);\n```\n\n### Get maximum extended attribute value size in bytes\n\n```java\nXAttr4J.xattrsizebits(path);\nXAttr4J.fxattrsizebits(fd);\n```\n\n\u0026nbsp;\n\nThere're also [fd](https://en.wikipedia.org/wiki/File_descriptor)-oriented xattr operations, i.e. `fgetxattr`, `fsetxattr`, `fremovexattr`, `flistxattr`, `fsizexattr`, `fexistxattr` are available, usage omitted(similar to path-oriented xattr operations).\n\n# Test\n\nAll test cases require [Google's Guava](https://github.com/google/guava) library to compile.\n\n```shell\nmake tests\n```\n\nFeel free to [submit an issue](issues/new)(with *bug* label) if any test failed.\n\n# Caveats\n\n* This `xattr4j` implementation claims to be compatible with [UserDefinedFileAttributeView](https://docs.oracle.com/javase/7/docs/api/java/nio/file/attribute/UserDefinedFileAttributeView.html).\n\n* (macOS) Some file systems don't support xattr syscalls, Apple alternatively use a [AppleDouble format](https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats) for remedy, when you use any xattr syscalls for AppleDouble format file(or any `fd` backed by such a file), you'll got an errno 1([EPERM](https://opensource.apple.com/source/xnu/xnu-4570.71.2/bsd/sys/errno.h.auto.html)).\n\n* Java uses a [Modified UTF-8](https://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8) representation, when you pass a `java.lang.String` down to JNI and use `JNIEnv-\u003eGetStringUTFChars` to get its `char *` representation, and use it as first parameter xattr syscalls, you might got errno 2(ENOENT), since aforementioned `char *` is encoded in a modified UTF-8 form.\n\n\t`xattr4j` overcomed this flaw, we convert it into standard UTF-8 representation before call down to JNI.\n\n* For macOS \u003e= 10.14, please specify `ARCHS` to `-arch x86_64`, Apple droped `i386` library linkage starting from 10.14.\n\n\t```shell\n\tARCHS='-arch x86_64' make\n\t```\n\n# TODO\n\n- [x] (macOS) Add a JNI function to retrieve result of `pathconf(path, _PC_XATTR_SIZE_BITS)` and `fpathconf(fd, _PC_XATTR_SIZE_BITS)`?\n\n- [ ] Add a `javadoc` target into Makefile?\n\n- [ ] Add more sane test cases\n\n- [ ] Instead of throw an `IOException`, we may instead implement a `SystemErrorException`, and wrap up an `errno` when we throw such exception.\n\nFeel free to contribute to this repository. :-)\n\n# License\n\nSee [LICENSE](LICENSE)\n\n# *References*\n\n[UserDefinedFileAttributeView](https://docs.oracle.com/javase/7/docs/api/java/nio/file/attribute/UserDefinedFileAttributeView.html)\n\n[IsNull/xattrj](https://github.com/IsNull/xattrj)\n\n[12.108 Glibc `\u003csys/xattr.h\u003e`](https://www.gnu.org/software/gnulib/manual/html_node/Glibc-sys_002fxattr_002eh.html#Glibc-sys_002fxattr_002eh)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleiless%2Fxattr4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleiless%2Fxattr4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleiless%2Fxattr4j/lists"}