public String getLog() { return record.toString(); } }
/** * Works like {@link #encodeTo(Writer)} but obtain the result as a string. */ public String encode() throws IOException { return encodeToBytes().toString(); }
/** * Prints this note into a writer. * * <p> * Technically, this method only works if the {@link Writer} to {@link OutputStream} * encoding is ASCII compatible. */ public void encodeTo(Writer out) throws IOException { out.write(encodeToBytes().toString()); }
public String toString(Document document) throws IOException { org.apache.commons.io.output.ByteArrayOutputStream outputStream = new org.apache.commons.io.output.ByteArrayOutputStream(); XmlUtils.writeXml(document, outputStream); return outputStream.toString(StandardCharsets.UTF_8); }
public String configAsXml(CruiseConfig config, boolean skipPreprocessingAndValidation) throws Exception { LOGGER.debug("[Config Save] === Converting config to XML"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); magicalGoConfigXmlWriter.write(config, outputStream, skipPreprocessingAndValidation); LOGGER.debug("[Config Save] === Done converting config to XML"); return outputStream.toString(); }
private String getOutput(final String threadName) { final ByteArrayOutputStream output = m_outputMap.get(threadName); assertNotNull("getOutput()", output); return output.toString(StandardCharsets.UTF_8); }
@Override public void restart() throws IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstanceOrNull(); try { if (jenkins != null) { jenkins.cleanUp(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e); } File me = getHudsonWar(); File home = me.getParentFile(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Restarting a service"); String exe = System.getenv("WINSW_EXECUTABLE"); File executable; if (exe!=null) executable = new File(exe); else executable = new File(home, "hudson.exe"); if (!executable.exists()) executable = new File(home, "jenkins.exe"); // use restart! to run hudson/jenkins.exe restart in a separate process, so it doesn't kill itself int r = new LocalLauncher(task).launch().cmds(executable, "restart!") .stdout(task).pwd(home).join(); if(r!=0) throw new IOException(baos.toString()); }
int r = runElevated(new File(dir, "jenkins.exe"), "install", task, dir); if(r!=0) { sendError(baos.toString(),req,rsp); return;
@Test public void testWriteLines_Writer() throws Exception { final Object[] data = new Object[]{ "hello", new StringBuffer("world"), "", "this is", null, "some text"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); @SuppressWarnings("resource") // deliberately not closed final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, true, true); final Writer writer = new OutputStreamWriter(baout, "US-ASCII"); IOUtils.writeLines(list, "*", writer); out.off(); writer.flush(); final String expected = "hello*world**this is**some text*"; final String actual = baout.toString(); assertEquals(expected, actual); }
@Test public void testWriteLines_Writer_nullSeparator() throws Exception { final Object[] data = new Object[]{"hello", "world"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); @SuppressWarnings("resource") // deliberately not closed final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, true, true); final Writer writer = new OutputStreamWriter(baout, "US-ASCII"); IOUtils.writeLines(list, null, writer); out.off(); writer.flush(); final String expected = "hello" + IOUtils.LINE_SEPARATOR + "world" + IOUtils.LINE_SEPARATOR; final String actual = baout.toString(); assertEquals(expected, actual); }
@Test public void testWriteLines_OutputStream_Encoding_nullEncoding() throws Exception { final Object[] data = new Object[]{ "hello", new StringBuffer("world"), "", "this is", null, "some text"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); IOUtils.writeLines(list, "*", out, (String) null); out.off(); out.flush(); final String expected = "hello*world**this is**some text*"; final String actual = baout.toString(); assertEquals(expected, actual); }
@Test public void testWriteLines_OutputStream() throws Exception { final Object[] data = new Object[]{ "hello", new StringBuffer("world"), "", "this is", null, "some text"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); IOUtils.writeLines(list, "*", out); out.off(); out.flush(); final String expected = "hello*world**this is**some text*"; final String actual = baout.toString(); assertEquals(expected, actual); }
@Test public void testWriteLines_OutputStream_Encoding() throws Exception { final Object[] data = new Object[]{ "hello\u8364", new StringBuffer("world"), "", "this is", null, "some text"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); IOUtils.writeLines(list, "*", out, "UTF-8"); out.off(); out.flush(); final String expected = "hello\u8364*world**this is**some text*"; final String actual = baout.toString("UTF-8"); assertEquals(expected, actual); }
@Test public void testWriteLines_OutputStream_Encoding_nullSeparator() throws Exception { final Object[] data = new Object[]{"hello", "world"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); IOUtils.writeLines(list, null, out, "US-ASCII"); out.off(); out.flush(); final String expected = "hello" + IOUtils.LINE_SEPARATOR + "world" + IOUtils.LINE_SEPARATOR; final String actual = baout.toString(); assertEquals(expected, actual); }
@Test public void testWriteLines_OutputStream_nullSeparator() throws Exception { final Object[] data = new Object[]{"hello", "world"}; final List<Object> list = Arrays.asList(data); final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); IOUtils.writeLines(list, null, out); out.off(); out.flush(); final String expected = "hello" + IOUtils.LINE_SEPARATOR + "world" + IOUtils.LINE_SEPARATOR; final String actual = baout.toString(); assertEquals(expected, actual); }
final String baoutString = baout.toString("ASCII"); final String refString = ref.toString("ASCII"); assertEquals("ASCII decoded String must be equal", refString, baoutString);
private <K, V> String explainToString(Map<K, V> explainMap) throws Exception { ExplainWork work = new ExplainWork(); ParseContext pCtx = new ParseContext(); HashMap<String, TableScanOperator> topOps = new HashMap<>(); TableScanOperator scanOp = new DummyOperator(new DummyExplainDesc<K, V>(explainMap)); topOps.put("sample", scanOp); pCtx.setTopOps(topOps); work.setParseContext(pCtx); ByteArrayOutputStream baos = new ByteArrayOutputStream(); work.setConfig(new ExplainConfiguration()); ExplainTask newExplainTask = new ExplainTask(); newExplainTask.queryState = uut.queryState; newExplainTask.getJSONLogicalPlan(new PrintStream(baos), work); baos.close(); return baos.toString(); }
@Test public void testLogsNoParameter() throws IOException { main.run(new String[]{"logs", "--task"}); String result = outputStream.toString("UTF-8"); assertTrue(result.contains("Usage: logs [options]")); }
@Test public void testNonExistingCommand() throws IOException { main.run(new String[]{"foo"}); String result = outputStream.toString("UTF-8"); assertUsageText(result); assertFalse(result.contains("Failed to run command 'null'. null")); }