当前位置: 首页>>代码示例>>Java>>正文


Java OutputStream.toString方法代码示例

本文整理汇总了Java中java.io.OutputStream.toString方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStream.toString方法的具体用法?Java OutputStream.toString怎么用?Java OutputStream.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.OutputStream的用法示例。


在下文中一共展示了OutputStream.toString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toXML

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * 转为xml串
 *
 * @param obj
 * @return
 */
public String toXML(Object obj) {
	String result = null;
	try {
		JAXBContext context = JAXBContext.newInstance(obj.getClass());
		Marshaller m = context.createMarshaller();
		m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		m.setProperty(Marshaller.JAXB_FRAGMENT, true);// 去掉报文头
		OutputStream os = new ByteArrayOutputStream();
		XMLSerializer serializer = getXMLSerializer(os);
		m.marshal(obj, serializer.asContentHandler());
		result = os.toString();
	} catch (Exception e) {
		e.printStackTrace();
	}
	logger.info("response text:" + result);
	return result;
}
 
开发者ID:funtl,项目名称:framework,代码行数:25,代码来源:JaxbParser.java

示例2: verifyBlobWriteTo

import java.io.OutputStream; //导入方法依赖的package包/类
/** Checks that the {@link Blob} streams the expected string. */
private void verifyBlobWriteTo(String expected, Blob blob) throws IOException {
  OutputStream outputStream = new ByteArrayOutputStream();
  BlobDescriptor blobDescriptor = blob.writeTo(outputStream);

  String output = outputStream.toString();
  Assert.assertEquals(expected, output);

  byte[] expectedBytes = expected.getBytes(StandardCharsets.UTF_8);
  Assert.assertEquals(expectedBytes.length, blobDescriptor.getSize());

  CountingDigestOutputStream countingDigestOutputStream =
      new CountingDigestOutputStream(Mockito.mock(OutputStream.class));
  countingDigestOutputStream.write(expectedBytes);
  DescriptorDigest expectedDigest = countingDigestOutputStream.toBlobDescriptor().getDigest();
  Assert.assertEquals(expectedDigest, blobDescriptor.getDigest());
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:18,代码来源:BlobTest.java

示例3: printtoString

import java.io.OutputStream; //导入方法依赖的package包/类
void printtoString(InputStream istm) {

		int k;
		int aBuffSize = 11000;
		String StringFromWS = "";
		byte buff[] = new byte[aBuffSize];
		OutputStream xOutputStream = new ByteArrayOutputStream(aBuffSize);

		try {
			while ((k = istm.read(buff)) != -1)
				xOutputStream.write(buff, 0, k);

			// I can now grab the string I want
			StringFromWS = StringFromWS + xOutputStream.toString();
			System.out.println("\n\n\n\n\n String Content of the page is:");
			System.out.println(StringFromWS);
			System.out.println("\n\n\n\n\n\n\n");
		} catch (IOException e) {

			System.out.println("Exception in printtoString method. :" + e);

		}
	}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:24,代码来源:PageDesc.java

示例4: keyGen

import java.io.OutputStream; //导入方法依赖的package包/类
public Map<String,String> keyGen(String passPhrase, String pubDesc) {
	JSch jsch=new JSch();
       String passphrase= (passPhrase == null) ? "" : passPhrase;
       Map<String,String> result = new HashMap<String,String>();
       try{
        KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA, 2048);
        kpair.setPassphrase(passphrase);
        OutputStream prkos = new ByteArrayOutputStream();
        kpair.writePrivateKey(prkos);
        String privateKey = prkos.toString();
        //removing "\n" at the end of the string
        result.put("private", privateKey.substring(0, privateKey.length() - 1));
        OutputStream pubkos = new ByteArrayOutputStream();
        kpair.writePublicKey(pubkos, pubDesc);
        String pubKey = pubkos.toString();
        //removing "\n" at the end of the string
        result.put("public", pubKey.substring(0, pubKey.length() - 1));
        kpair.dispose();
        return result;
       } catch(Exception e){
       	System.out.println(e);
       	logger.error(e.getMessage());
       	throw new TransistorException(CmsError.TRANSISTOR_EXCEPTION, e.getMessage());
       }
}
 
开发者ID:oneops,项目名称:oneops,代码行数:26,代码来源:TransUtil.java

示例5: parseMetrics

import java.io.OutputStream; //导入方法依赖的package包/类
@Test
public void parseMetrics() throws IOException {
    final Counter counter = Counter
            .build("testcounter", "testdescription")
            .labelNames("one", "two")
            .register();
    counter.labels("1", "2").inc();
    final HttpExchange mockExchange = mock(HttpExchange.class);
    final OutputStream outputStream = new ByteArrayOutputStream();
    when(mockExchange.getResponseBody()).thenReturn(outputStream);
    final Headers headers = new Headers();
    when(mockExchange.getResponseHeaders()).thenReturn(headers);

    new PrometheusWebConsole().getServlet().handle(mockExchange);

    assertEquals(TextFormat.CONTENT_TYPE_004, headers.get("Content-Type").get(0));

    final String response = outputStream.toString();
    assertTrue(response.contains("# HELP testcounter testdescription"));
    assertTrue(response.contains("# TYPE testcounter counter"));
    assertTrue(response.contains("one=\"1\""));
    assertTrue(response.contains("two=\"2\""));
}
 
开发者ID:secondbase,项目名称:secondbase,代码行数:24,代码来源:PrometheusWebConsoleTest.java

示例6: test_to_default

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Tests the app configuration serialization to a resource.
 * In this test the configuration file provides with complete default settings.
 */
@Test
public void test_to_default() throws IOException {
  InputStream injson = AppConfigurationServiceTest.class.getResourceAsStream("/config/default.check.json");
  InputStream inyaml = AppConfigurationServiceTest.class.getResourceAsStream("/config/default.check.yaml");

  AppConfiguration config = new AppConfiguration();

  OutputStream outjson = new ByteArrayOutputStream();
  OutputStream outyaml = new ByteArrayOutputStream();
  AppConfigurationService.to(AppConfigurationFormat.JSON, outjson, config);
  AppConfigurationService.to(AppConfigurationFormat.YAML, outyaml, config);
  String actualJson = outjson.toString();
  String actualYaml = outyaml.toString();

  String expectedJson = IOUtils.toString(injson, Charset.defaultCharset());
  String expectedYaml = IOUtils.toString(inyaml, Charset.defaultCharset());

  Assert.assertEquals(expectedJson, actualJson);
  Assert.assertEquals(expectedYaml, actualYaml);
}
 
开发者ID:braineering,项目名称:ares,代码行数:25,代码来源:AppConfigurationServiceTest.java

示例7: a

import java.io.OutputStream; //导入方法依赖的package包/类
public String a(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    jn.a(inputStream, byteArrayOutputStream);
    return byteArrayOutputStream.toString();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:iw.java

示例8: body

import java.io.OutputStream; //导入方法依赖的package包/类
public String body(String charset) throws HttpRequestException {
    OutputStream output = byteStream();
    try {
        copy(buffer(), output);
        return output.toString(getValidCharset(charset));
    } catch (IOException e) {
        throw new HttpRequestException(e);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:10,代码来源:HttpRequest.java

示例9: test_to_custom

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Tests the app configuration serialization from a resource.
 * In this test the configuration file provides with complete custom settings.
 * The configuration file has non-null values and template string (${RES}).
 */
@Test
public void test_to_custom() throws IOException, ParseException {
  InputStream injson = AppConfigurationServiceTest.class.getResourceAsStream("/config/custom.check.json");
  InputStream inyaml = AppConfigurationServiceTest.class.getResourceAsStream("/config/custom.check.yaml");

  AppConfiguration expected = new AppConfiguration();
  expected.setCnfInfo(true);
  expected.setTgtInfo(true);
  expected.setSysInfo(false);
  expected.setNetInfo(false);
  expected.setPolling(new Interval(10, 15, TimeUnit.SECONDS));
  expected.setReconnections(5L);
  expected.setReconnectionWait(new Interval(10, 15, TimeUnit.SECONDS));
  expected.setProxy(new HttpProxy("192.168.0.1", 8080));
  expected.setAuthentication(new HashMap<String,String>(){{put("User-Agent", "CustomUserAgent");}});
  List<Controller> controllers = new ArrayList<>();
  Controller controller1 = new Controller(
      "init", "cmd", "log");
  Controller controller2 = new Controller(
      "init2", "cmd2", "log2",
      new Interval(10, 20, TimeUnit.SECONDS),
      10L,
      new Interval(10, 20, TimeUnit.SECONDS),
      HttpProxy.NONE,
      null,
      null);
  Controller controller3 = new Controller(
      "init3", "cmd3", "log3",
      new Interval(10, 20, TimeUnit.SECONDS),
      10L,
      new Interval(10, 20, TimeUnit.SECONDS),
      new HttpProxy("192.168.0.1", 8080),
      "* * * ? * SAT,SUN",
      new HashMap<String,String>(){{put("User-Agent", "CustomUserAgent");}});
  controllers.add(controller1);
  controllers.add(controller2);
  controllers.add(controller3);
  expected.setControllers(controllers);

  OutputStream outjson = new ByteArrayOutputStream();
  OutputStream outyaml = new ByteArrayOutputStream();
  AppConfigurationService.to(AppConfigurationFormat.JSON, outjson, expected);
  AppConfigurationService.to(AppConfigurationFormat.YAML, outyaml, expected);
  String actualJson = outjson.toString();
  String actualYaml = outyaml.toString();

  String expectedJson = IOUtils.toString(injson, Charset.defaultCharset());
  String expectedYaml = IOUtils.toString(inyaml, Charset.defaultCharset());

  Assert.assertEquals(expectedJson, actualJson);
  Assert.assertEquals(expectedYaml, actualYaml);
}
 
开发者ID:braineering,项目名称:ares,代码行数:58,代码来源:AppConfigurationServiceTest.java


注:本文中的java.io.OutputStream.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。