public InputStream downloadFileFromStorage(String jarName) throws IOException { return fileStorage.download(jarName); }
@Override public InputStream downloadFile(String fileId) throws IOException { return fileStorage.download(fileId); }
public InputStream getFileFromJarStorage(String fileName) throws IOException { return this.fileStorage.download(fileName); }
public InputStream downloadFileFromStorage(String jarName) throws IOException { return fileStorage.download(jarName); }
private void downloadAndCopyJars (Set<String> jarsToDownload, Path destinationPath) throws IOException { Set<String> copiedJars = new HashSet<>(); for (String jar: jarsToDownload) { if (!copiedJars.contains(jar)) { Path jarPath = Paths.get(jar); if (destinationPath == null || jarPath == null) { throw new IllegalArgumentException("null destinationPath or jarPath"); } Path jarFileName = jarPath.getFileName(); if (jarFileName == null) { throw new IllegalArgumentException("null farFileName"); } File destPath = Paths.get(destinationPath.toString(), jarFileName.toString()).toFile(); try (InputStream src = fileStorage.download(jar); FileOutputStream dest = new FileOutputStream(destPath) ) { IOUtils.copy(src, dest); copiedJars.add(jar); LOG.debug("Jar {} copied to {}", jar, destPath); } } } }
@Test public void testJarStorage() throws IOException { FileStorage fileStorage = getFileStorage(); File file = File.createTempFile("test", ".tmp"); file.deleteOnExit(); List<String> lines = Lists.newArrayList("test-line-1", "test-line-2"); Files.write(file.toPath(), lines, Charset.forName("UTF-8")); String name = "file.name"; // delete the file if it already exists fileStorage.delete(name); fileStorage.upload(new FileInputStream(file), name); InputStream inputStream = fileStorage.download(name); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String nextLine; List<String> actual = Lists.newArrayList(); while((nextLine = bufferedReader.readLine()) != null) { actual.add(nextLine); } Assert.assertEquals(lines, actual); } }