/** * @see #copyResource(Map, InputStream, String, boolean) */ public int copyResource(Map<Object,Object> sshFlags, Reader source, String target, boolean createParent) { return copyResource(sshFlags, new ReaderInputStream(source), target, createParent); }
/** * Reads from the {@link Reader}, returning the same value. * * @return the value of the next character in the {@link Reader}. * * @exception IOException if the original {@link Reader} fails to be read */ @Override public synchronized int read() throws IOException { if (in == null) { throw new IOException("Stream Closed"); } byte result; if (slack != null && begin < slack.length) { result = slack[begin]; if (++begin == slack.length) { slack = null; } } else { byte[] buf = new byte[1]; if (read(buf, 0, 1) <= 0) { result = -1; } result = buf[0]; } if (result < -1) { result += 256; } return result; }
public int copyTo(Map<String,?> props, Reader src, String destination) { return copyTo(props, new ReaderInputStream(src), destination); } public int copyTo(InputStream src, String destination) {
public SshPutTaskFactory contents(Reader reader) { markDirty(); this.contents = Suppliers.ofInstance(new ReaderInputStream(reader)); return self(); }
private Document parseXml(String plan) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document dom; try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = db.parse(new ReaderInputStream(new StringReader(plan))); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new UnsupportedTypePlanException(e); } return dom; }
private Document parseXml(String plan) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document dom; try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = db.parse(new ReaderInputStream(new StringReader(plan))); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new UnsupportedTypePlanException(e); } return dom; }
@Test(groups={"Integration","Broken"}) public void testStopCommandWaitsToStopWithSigTerm() { StopCommandSoftwareProcess entity = app.createAndManageChild(EntitySpec.create(StopCommandSoftwareProcess.class, StopCommandSoftwareProcessImpl.class)); entity.start(ImmutableList.of(loc)); VanillaSoftwareProcessSshDriver driver = (VanillaSoftwareProcessSshDriver) entity.getDriver(); String launchContents = Joiner.on('\n') .join("#!/usr/bin/env bash", "function trap_handler_command {", " echo stopping...", " exit 13", "}", "trap \"trap_handler_command\" SIGTERM", "while true; do", " sleep 1", "done"); driver.copyResource(ImmutableMap.of(), new ReaderInputStream(new StringReader(launchContents), "UTF-8"), "launch.sh", true); driver.executeLaunchCommand("nohup bash launch.sh > /dev/null &"); ScriptHelper stopCommandScriptHelper = driver.stopCommandScriptHelper(); stopCommandScriptHelper.execute(); assertEquals(StringUtils.countMatches(stopCommandScriptHelper.getResultStdout(), "Attempted to stop PID"), 1, "SIGTERM should be tried one time"); assertFalse(stopCommandScriptHelper.getResultStdout().contains("stopped with SIGKILL"), "SIGKILL should not be sent after SIGTERM fails."); SshMachineLocation machineLocation = (SshMachineLocation) Iterables.getFirst(entity.getLocations(), null); int checkPidFileExitCode = machineLocation.execCommands("Check for pid file", ImmutableList.of("ls " + driver.getRunDir() + '/' + VanillaSoftwareProcessSshDriver.PID_FILENAME)); assertEquals(checkPidFileExitCode, 2, "pid file should be deleted."); }
" sleep 1", "done"); driver.copyResource(ImmutableMap.of(), new ReaderInputStream(new StringReader(launchContents), "UTF-8"), "launch.sh", true); driver.executeLaunchCommand("nohup bash launch.sh > /dev/null &"); ByteArrayOutputStream stdOut = new ByteArrayOutputStream(15);