@Override public void open(final Host host, final Path workdir) throws AccessDeniedException { throw new LocalAccessDeniedException("Disabled"); } }
@Override public OutputStream getOutputStream(boolean append) throws AccessDeniedException { final NSURL resolved; try { resolved = this.lock(this.exists()); if(null == resolved) { return super.getOutputStream(append); } } catch(LocalAccessDeniedException e) { log.warn(String.format("Failure obtaining lock for %s. %s", this, e.getMessage())); return super.getOutputStream(append); } try { return new ProxyOutputStream(new FileOutputStream(new File(resolved.path()), append)) { @Override public void close() throws IOException { try { super.close(); } finally { release(resolved); } } }; } catch(FileNotFoundException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }
log.warn(String.format("Failure cleaning up previous application support directory. %s", e.getMessage()));
log.warn(String.format("Failure to quarantine file %s. %s", file, e.getMessage()));
protected InputStream getInputStream(final String path) throws LocalAccessDeniedException { try { final FileChannel channel = FileChannel.open(Paths.get(path), StandardOpenOption.READ); return new SeekableByteChannelInputStream(channel); } catch(IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }
@Override public void trash(Local file) throws LocalAccessDeniedException { try { Files.delete(Paths.get(file.getAbsolute())); } catch(IOException e) { throw new LocalAccessDeniedException(String.format("Failed to move %s to Trash", file.getName()), e); } } }
public void setModificationDate(final long timestamp) throws AccessDeniedException { if(timestamp < 0) { return; } try { Files.setLastModifiedTime(Paths.get(path), FileTime.fromMillis(timestamp)); } catch(IOException e) { throw new LocalAccessDeniedException(String.format("Cannot change timestamp of %s", path), e); } }
public void setPermission(final Permission permission) throws AccessDeniedException { if(FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { try { Files.setPosixFilePermissions(Paths.get(path), PosixFilePermissions.fromString(permission.getSymbol())); } catch(IllegalArgumentException | IOException e) { throw new LocalAccessDeniedException(String.format("Cannot change permissions of %s", path), e); } } }
protected OutputStream getOutputStream(final String path, final boolean append) throws LocalAccessDeniedException { try { final Set<OpenOption> options = new HashSet<>(); options.add(StandardOpenOption.WRITE); if(!this.exists()) { options.add(StandardOpenOption.CREATE); } if(append) { options.add(StandardOpenOption.APPEND); } else { options.add(StandardOpenOption.TRUNCATE_EXISTING); } final FileChannel channel = FileChannel.open(Paths.get(path), options); return Channels.newOutputStream(channel); } catch(IOException e) { throw new LocalAccessDeniedException(e.getMessage(), e); } }
@Override public BackgroundException map(final IOException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if(e instanceof NoSuchFileException) { return new NotfoundException(buffer.toString(), e); } if(e instanceof FileSystemException) { return new LocalAccessDeniedException(buffer.toString(), e); } return this.wrap(e, buffer); } }
@Override public void mkdir(final Local file) throws AccessDeniedException { try { Files.createDirectories(Paths.get(file.getAbsolute())); } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format(LocaleFactory.localizedString( "Cannot create folder {0}", "Error"), file.getName()), e); } } }
@Override public void removeAll() throws LocalAccessDeniedException { if(log.isDebugEnabled()) { log.debug(String.format("Remove all our added items in %s", this.forList(list))); } if(!this.removeAllItems(this.forList(list))) { throw new LocalAccessDeniedException(String.format("Failure removing all items from %s", this.forList(list))); } }
/** * Delete the file */ public void delete() throws AccessDeniedException, NotfoundException { try { Files.delete(Paths.get(path)); } catch(NoSuchFileException e) { throw new LocalNotfoundException(String.format("Delete %s failed", path), e); } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot delete {0}", "Error"), this.getName()), e); } }
@Override public void add(final Local file) throws LocalAccessDeniedException { if(log.isDebugEnabled()) { log.debug(String.format("Add %s to %s", file, this.forList(list))); } if(!this.addItem(file.getAbsolute(), this.forList(list))) { throw new LocalAccessDeniedException(String.format("Failure adding %s to %s", file, this.forList(list))); } }
@Override public void remove(final Local file) throws LocalAccessDeniedException { if(log.isDebugEnabled()) { log.debug(String.format("Remove %s in %s", file, this.forList(list))); } if(!this.removeItem(file.getAbsolute(), this.forList(list))) { throw new LocalAccessDeniedException(String.format("Failure removing %s from %s", file, this.forList(list))); } }
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { NSDictionary serialized = NSDictionary.dictionaryWithContentsOfFile(file.getAbsolute()); if(null == serialized) { throw new LocalAccessDeniedException(String.format("Invalid bookmark file %s", file)); } this.parse(protocols, serialized); }
/** * Set the kMDItemWhereFroms on the file. * * @param dataUrl Href where the file was downloaded from */ @Override public void setWhereFrom(final Local file, final String dataUrl) throws LocalAccessDeniedException { synchronized(lock) { if(StringUtils.isBlank(dataUrl)) { log.warn("No data url given"); return; } if(!this.setWhereFrom(file.getAbsolute(), dataUrl)) { throw new LocalAccessDeniedException(file.getAbsolute()); } } }
public void rename(final Local renamed) throws AccessDeniedException { try { try { Files.move(Paths.get(path), Paths.get(renamed.getAbsolute()), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); } // Catch generic exception due to a bug in IKVM moving files containing special characters // in conjunction with the atomic move option catch(FileSystemException e) { // Copying file to different disk is not possible with atomic move. // Moving directory to an already existing target will throw exists exception with atomic move flag. Files.move(Paths.get(path), Paths.get(renamed.getAbsolute()), StandardCopyOption.REPLACE_EXISTING); } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Cannot rename {0}", "Error"), this.getName()), e); } path = renamed.getAbsolute(); }
/** * @param originUrl The URL of the resource originally hosting the quarantined item, from the user's point of * view. The origin URL should not be set to the data URL, or the quarantining application may start * downloading the file again if the user chooses to view the origin URL while resolving a quarantine * warning. * @param dataUrl The URL from which the data for the quarantined item data was * actaully streamed or downloaded, if available */ @Override public void setQuarantine(final Local file, final String originUrl, final String dataUrl) throws LocalAccessDeniedException { if(StringUtils.isEmpty(originUrl)) { log.warn("No origin url given for quarantine"); return; } if(StringUtils.isEmpty(dataUrl)) { log.warn("No data url given for quarantine"); return; } synchronized(lock) { if(!this.setQuarantine(file.getAbsolute(), originUrl, dataUrl)) { throw new LocalAccessDeniedException(file.getAbsolute()); } } }
proxy.invoke(action, action.lock(), true); if(selected.get() == null) { throw new LocalAccessDeniedException(String.format("Prompt for %s canceled", file));