org.apache.commons.io.output.ByteArrayOutputStream.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(205)

本文整理了Java中org.apache.commons.io.output.ByteArrayOutputStream.toString()方法的一些代码示例,展示了ByteArrayOutputStream.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.toString()方法的具体详情如下:
包路径:org.apache.commons.io.output.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:toString

ByteArrayOutputStream.toString介绍

[英]Gets the curent contents of this byte stream as a string.
[中]以字符串形式获取此字节流的当前内容。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public String getLog() {
    return record.toString();
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Works like {@link #encodeTo(Writer)} but obtain the result as a string.
 */
public String encode() throws IOException {
  return encodeToBytes().toString();
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * 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());
}

代码示例来源:origin: gocd/gocd

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);
}

代码示例来源:origin: gocd/gocd

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();
}

代码示例来源:origin: commons-io/commons-io

private String getOutput(final String threadName) {
  final ByteArrayOutputStream output =
      m_outputMap.get(threadName);
  assertNotNull("getOutput()", output);
  return output.toString(StandardCharsets.UTF_8);
}

代码示例来源:origin: jenkinsci/jenkins

@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());
}

代码示例来源:origin: jenkinsci/jenkins

int r = runElevated(new File(dir, "jenkins.exe"), "install", task, dir);
if(r!=0) {
  sendError(baos.toString(),req,rsp);
  return;

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: jenkinsci/jenkins

if(ze.getCode()==ErrorCode.EZFS_PERM) {
    req.setAttribute("message",log.toString());
    rsp.forward(this,"askRootPassword",req);
    return;
sendError(log.toString(),req,rsp);
return;

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: commons-io/commons-io

@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);
}

代码示例来源:origin: commons-io/commons-io

final String baoutString = baout.toString("ASCII");
final String refString = ref.toString("ASCII");
assertEquals("ASCII decoded String must be equal", refString, baoutString);

代码示例来源:origin: apache/hive

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();
}

代码示例来源:origin: ContainerSolutions/minimesos

@Test
public void testLogsNoParameter() throws IOException {
  main.run(new String[]{"logs", "--task"});
  String result = outputStream.toString("UTF-8");
  assertTrue(result.contains("Usage: logs [options]"));
}

代码示例来源:origin: ContainerSolutions/minimesos

@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"));
}

相关文章