@Test public void testRun() throws Exception { final File unitDirectory = new File("target/unit"); FileUtils.forceMkdir(unitDirectory); final File targetFile = new File(unitDirectory, "download.test"); if (targetFile.exists()) { assertThat(targetFile.delete()).isTrue(); } final FileRequest mockRequest = mock(FileRequest.class); when(mockRequest.getSourceFile()).thenReturn(URI.create("target/unit/dummy.src")); when(mockRequest.getTargetFile()).thenReturn(targetFile.toURI()); final ChannelSftp mockChannel = mock(ChannelSftp.class); when(mockChannel.get(mockRequest.getSourceFile().getPath())) .thenReturn(DownloadProcessorTest.class.getResourceAsStream("test.txt")); final DownloadProcessor processor = new DownloadProcessor(mockRequest); processor.run(mockChannel); assertThat(targetFile.exists()).isTrue(); assertThat(FileUtils.readLines(targetFile, "UTF-8")).containsOnly("This is a test."); }
@Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } DownloadProcessor(final FileRequest request); }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } DownloadProcessor(final FileRequest request); @Override void run(final ChannelSftp channel); }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } DownloadProcessor(final FileRequest request); @Override void run(final ChannelSftp channel);  }