ResourceUtils { private InputStream getResourceViaSftp(String url) throws IOException { assert url.startsWith("sftp: String subUrl = url.substring("sftp: String user; String address; String path; int atIndex = subUrl.indexOf("@"); int colonIndex = subUrl.indexOf(":", (atIndex > 0 ? atIndex : 0)); if (colonIndex <= 0 || colonIndex <= atIndex) { throw new IllegalArgumentException("Invalid sftp url ("+url+"); IP or hostname must be specified, such as sftp: } if (subUrl.length() <= (colonIndex+1)) { throw new IllegalArgumentException("Invalid sftp url ("+url+"); must specify path of remote file, such as sftp: } if (atIndex >= 0) { user = subUrl.substring(0, atIndex); } else { user = null; } address = subUrl.substring(atIndex + 1, colonIndex); path = subUrl.substring(colonIndex+1); SshMachineLocation machine = new SshMachineLocation(MutableMap.builder() .putIfNotNull("user", user) .put("address", InetAddress.getByName(address)) .build()); try { final File tempFile = Os.newTempFile("brooklyn-sftp", "tmp"); tempFile.setReadable(true, true); machine.copyFrom(path, tempFile.getAbsolutePath()); return new FileInputStream(tempFile) { @Override public void close() throws IOException { super.close(); tempFile.delete(); } }; } finally { Streams.closeQuietly(machine); } } ResourceUtils(ClassLoader loader, Object contextObject, String contextMessage);  ResourceUtils(BrooklynClassLoadingContext loader, Object contextObject, String contextMessage);  ResourceUtils(Object contextObject, String contextMessage);  ResourceUtils(Object contextObject); static final ResourceUtils create(ClassLoader loader, Object contextObject, String contextMessage); static final ResourceUtils create(BrooklynClassLoadingContext loader, Object contextObject, String contextMessage); static final ResourceUtils create(Object contextObject, String contextMessage); static final ResourceUtils create(Object contextObject); static final ResourceUtils create(); static void addClassLoaderProvider(Function<Object,BrooklynClassLoadingContext> provider); Iterable<URL> getResources(String name); InputStream getResourceFromUrl(String url,
            @Nullable org.apache.brooklyn.util.http.auth.Credentials credentials); InputStream getResourceFromUrl(String url); static URL tidy(URL url); static String tidyFileUrl(String url); String getResourceAsString(String url); String checkUrlExists(String url); String checkUrlExists(String url, String message); boolean doesUrlExist(String url); Optional<String> firstAvailableUrl(String ...urls); String getClassLoaderDir(); String getClassLoaderDir(String resourceInThatDir); static URL getContainerUrl(URL url, String resourceInThatDir);  }
@Test(groups="Integration") public void testGetResourceViaSftp() throws Exception { InputStream stream = utils.getResourceFromUrl("sftp: assertEquals(Streams.readFullyStringAndClose(stream), tempFileContents); }