@Test public void testTouch() throws Exception { final Path home = new SFTPHomeDirectoryService(session).find(); final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new SFTPTouchFeature(session).touch(test, new TransferStatus()); new SFTPUnixPermissionFeature(session).setUnixPermission(test, new Permission("664")); new SFTPTouchFeature(session).touch(test, new TransferStatus()); final AttributedList<Path> list = new SFTPListService(session).list(home, new DisabledListProgressListener()); assertTrue(list.contains(test)); assertEquals("664", list.get(test).attributes().getPermission().getMode()); new SFTPDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); }
SFTPTouchFeature implements Touch<Void> { @Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); } }
SFTPTouchFeature implements Touch<Void> { @Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); } SFTPTouchFeature(final SFTPSession session); }
SFTPTouchFeature implements Touch<Void> { @Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); } SFTPTouchFeature(final SFTPSession session); @Override Path touch(final Path file, final TransferStatus status); @Override SFTPTouchFeature withWriter(final Write writer); }
SFTPTouchFeature implements Touch<Void> { @Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(file.isFile()) { try { final FileAttributes attrs; if(Permission.EMPTY != status.getPermission()) { attrs = new FileAttributes.Builder().withPermissions(Integer.parseInt(status.getPermission().getMode(), 8)).build(); } else { attrs = FileAttributes.EMPTY; } final RemoteFile handle = session.sftp().open(file.getAbsolute(), EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE), attrs); handle.close(); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Cannot create file {0}", e, file); } } return new Path(file.getParent(), file.getName(), file.getType(), new SFTPAttributesFinderFeature(session).find(file)); } SFTPTouchFeature(final SFTPSession session); @Override Path touch(final Path file, final TransferStatus status); @Override SFTPTouchFeature withWriter(final Write writer);  }