public boolean writeToFile(String path) { return this.writeToFile_atomically(path, true); }
public boolean writeToURL(NSURL url) { return this.writeToURL_atomically(url, true); }
public static NSData dataWithBase64EncodedString(String base64String) { return CLASS.alloc().initWithBase64Encoding(base64String); }
@Override public String create(final Local file) throws AccessDeniedException { final ObjCObjectByReference error = new ObjCObjectByReference(); // Create new security scoped bookmark final NSURL url = NSURL.fileURLWithPath(file.getAbsolute()); if(log.isTraceEnabled()) { log.trace(String.format("Resolved file %s to url %s", file, url)); } final NSData data = url.bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error( create, null, null, error); if(null == data) { log.warn(String.format("Failure getting bookmark data for file %s", file)); final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(file.getAbsolute()); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } final String encoded = data.base64Encoding(); if(log.isTraceEnabled()) { log.trace(String.format("Encoded bookmark for %s as %s", file, encoded)); } return encoded; }
@Override public NSURL resolve(final Local file, final boolean interactive) throws AccessDeniedException { final NSData bookmark; if(null == file.getBookmark()) { log.warn(String.format("Missing security scoped bookmark for file %s", file)); if(interactive) { // Prompt user if no bookmark reference is available final String reference = this.choose(file); file.setBookmark(reference); bookmark = NSData.dataWithBase64EncodedString(reference); } else { throw new LocalAccessDeniedException(String.format("No security scoped bookmark for %s", file.getName())); } } else { bookmark = NSData.dataWithBase64EncodedString(file.getBookmark()); } final ObjCObjectByReference error = new ObjCObjectByReference(); final NSURL resolved = NSURL.URLByResolvingBookmarkData(bookmark, resolve, error); if(null == resolved) { log.warn(String.format("Error resolving bookmark for %s to URL", file)); final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(file.getAbsolute()); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } return resolved; }