LocalCommand implements ICommand { @Override public void copy(String sourcePath, String targetPath) throws IOException { if(logger.isDebugEnabled()) { logger.debug("local copy from " + sourcePath + " to " + targetPath); } File tDestFile = new File(targetPath); File tSourceFile = new File(sourcePath); if (!tDestFile.exists()) { tDestFile.createNewFile(); } FileChannel source = null; FileChannel destination = null; try { source = new FileInputStream(tSourceFile).getChannel(); destination = new FileOutputStream(tDestFile).getChannel(); destination.transferFrom(source, 0, source.size()); } finally { if (source != null) { source.close(); } if (destination != null) { destination.close(); } } if(logger.isDebugEnabled()) { logger.debug("local copy done "); } } LocalCommand(); @Override ShellCommandResult execShellCommand(String strCommand); @Override ShellCommandResult execShellCommand(String strCommand, String workingDir); @Override void copy(String sourcePath, String targetPath); @Override String getImplementationType(); @Override void disconnect();  }
@Test public void testCopy() throws Exception { assertNotNull(cmd); File fTemp = File.createTempFile("test", ".tmp"); File fTempDest = new File(fTemp.getAbsolutePath()+".bak"); cmd.copy(fTemp.getAbsolutePath(), fTempDest.getAbsolutePath()); assertTrue(fTempDest.exists()); fTempDest.delete(); }