/** @deprecated since 0.7.0; use same method in {@link Os} */ @Deprecated public static File writeToTempFile(InputStream is, String prefix, String suffix) { return Os.writeToTempFile(is, prefix, suffix); }
/** @deprecated since 0.7.0; use same method in {@link Os} */ @Deprecated public static File writeToTempFile(InputStream is, File tempDir, String prefix, String suffix) { return Os.writeToTempFile(is, tempDir, prefix, suffix); }
protected File writeTempFile(InputStream contents) { File tempFile = Os.writeToTempFile(contents, localTempDir, "sshcopy", "data"); tempFile.setReadable(false, false); tempFile.setReadable(true, true); tempFile.setWritable(false); tempFile.setExecutable(false); return tempFile; }
private static String cacheFile(String url) { InputStream in = getUrlStream(url); File cache = Os.writeToTempFile(in, "bundle-cache", "jar"); return cache.toURI().toString(); }
/** writes given contents to a temporary file which will be deleted on exit */ public static File writeToTempFile(InputStream is, String prefix, String suffix) { return writeToTempFile(is, new File(Os.tmp()), prefix, suffix); }
private File generateSimpleBomFile(String itemName, String itemVersion) { String catalogContents = Joiner.on("\n").join( "brooklyn.catalog:", " id: "+itemName, " version: "+itemVersion, " itemType: entity", " item:", " services:", " - type: org.apache.brooklyn.entity.stock.BasicApplication"); File bomFile = Os.writeToTempFile(new ByteArrayInputStream(catalogContents.getBytes()), "testAddToCatalog", ".bom"); filesToDelete.add(bomFile); return bomFile; }
@Test public void testWriteStreamToTempFile() throws Exception { File tempFileLocal = Os.writeToTempFile(new ByteArrayInputStream("mycontents".getBytes()), "resourceutils-test", ".txt"); try { List<String> lines = Files.readLines(tempFileLocal, Charsets.UTF_8); assertEquals(lines, ImmutableList.of("mycontents")); } finally { tempFileLocal.delete(); } }
@BeforeClass(alwaysRun=true) public void setUp() throws Exception { utils = ResourceUtils.create(this, "mycontext"); tempFile = Os.writeToTempFile(new ByteArrayInputStream(tempFileContents.getBytes()), "resourceutils-test", ".txt"); }
/** not much fun without a REST server. * but TODO we should make it so a different REST endpoint could be configured. * or better, use node js launchers in that project (likely to come with a new ui.) * <p> * relative path to webapp assumes brooklyn-server has been checked out at the same level as brooklyn-ui; * see {@link BrooklynRestApiLauncher#findJsguiWebappInSource()} */ public static Server startJavascriptWithoutRest() throws Exception { WebAppContext context = new WebAppContext( BrooklynRestApiLauncher.findJsguiWebappInSource().isPresent() ? BrooklynRestApiLauncher.findJsguiWebappInSource().get() : ResourceUtils.create(BrooklynJavascriptGuiLauncher.class).doesUrlExist("classpath://brooklyn.war") ? Os.writeToTempFile(ResourceUtils.create(BrooklynJavascriptGuiLauncher.class).getResourceFromUrl("classpath://brooklyn.war"), "brooklyn", "war").getAbsolutePath() : throwingReturning("could not find jsgui war or source", "missing-brooklyn.war"), "/"); context.setSecurityHandler(new NopSecurityHandler()); Server server = new Server(new InetSocketAddress(Networking.LOOPBACK, Networking.nextAvailablePort(FAVOURITE_PORT))); BrooklynRestApiLauncher.initJaasLoginService(server); server.setHandler(context); server.start(); log.info("JS GUI server started (no REST) at http://localhost:"+((NetworkConnector)server.getConnectors()[0]).getLocalPort()+"/"); return server; }
File tmpWarFile = Os.writeToTempFile( ResourceUtils.create(this).getResourceFromUrl(ROOT_WAR_URL), "TestHttpService",
private void installWar(WebAppContext context) { // here we run with the JS GUI, for convenience, if we can find it, else set up an empty dir // TODO pretty sure there is an option to monitor this dir and load changes to static content // NOTE: When running Brooklyn from an IDE (i.e. by launching BrooklynJavascriptGuiLauncher.main()) // you will need to ensure that the working directory is set to the brooklyn-ui repo folder. For IntelliJ, // set the 'Working directory' of the Run/Debug Configuration to $MODULE_DIR$/brooklyn-server/launcher. // For Eclipse, use the default option of ${workspace_loc:brooklyn-launcher}. // If the working directory is not set correctly, Brooklyn will be unable to find the jsgui .war // file and the 'gui not available' message will be shown. context.setWar(this.deployJsgui && findJsguiWebappInSource().isPresent() ? findJsguiWebappInSource().get() : ResourceUtils.create(this).doesUrlExist("classpath://brooklyn.war") ? Os.writeToTempFile(ResourceUtils.create(this).getResourceFromUrl("classpath://brooklyn.war"), "brooklyn", "war").getAbsolutePath() : createTempWebDirWithIndexHtml("Brooklyn REST API <p> (gui not available)")); }