/** * Convenience Method for move(dest, false). */ public Node move(Node dest) throws NodeNotFoundException, MoveException { return move(dest, false); }
/** * Uses copy/remove to move between file systems. * @return dest */ @Override public Node move(Node destNode, boolean overwrite) throws NodeNotFoundException, MoveException { FileNode dest; if (!(destNode instanceof FileNode)) { return super.move(destNode, overwrite); } dest = (FileNode) destNode; if (!overwrite) { try { dest.checkNotExists(); } catch (IOException e) { throw new MoveException(this, dest, "dest exists", e); } } try { Files.move(path, dest.path, StandardCopyOption.ATOMIC_MOVE); } catch (AtomicMoveNotSupportedException e) { return super.move(destNode, overwrite); } catch (NoSuchFileException e) { throw new FileNotFoundException(this, e); } catch (IOException e) { throw new MoveException(this, dest, "os command failed", e); } return dest; }
public void moveInto(Node directory) throws ExistsException, NodeNotFoundException, MoveException { directory.checkDirectory(); move(directory.join(getName())); }
@Override public Node move(Node destNode, boolean override) throws NodeNotFoundException, MoveException { SshNode dest; ChannelSftp sftp; if (destNode instanceof SshNode) { dest = (SshNode) destNode; try { if (!exists()) { throw new NodeNotFoundException(this); } if (!override) { dest.checkNotExists(); } sftp = alloc(); try { sftp.rename(escape(slashPath), escape(dest.slashPath)); } finally { free(sftp); } } catch (NodeNotFoundException e) { throw e; } catch (SftpException | JSchException | IOException e) { throw new MoveException(this, dest, "ssh failure", e); } return dest; } else { super.move(destNode, override); return destNode; } }