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


Java ByteArrayOutputStream.toString方法代码示例

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


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

示例1: uncompressToString

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static String uncompressToString(byte[] b, String encoding) {
	if (b == null || b.length == 0) {
		return null;
	}
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	ByteArrayInputStream in = new ByteArrayInputStream(b);
	try {
		GZIPInputStream gunzip = new GZIPInputStream(in);
		byte[] buffer = new byte[256];
		int n;
		while ((n = gunzip.read(buffer)) >= 0) {
			out.write(buffer, 0, n);
		}
		return out.toString(encoding);
	} catch (IOException e) {
		log.error(e.getMessage(),e);
	}
	return null;
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:20,代码来源:MessageGZIP.java

示例2: validateSnapshot

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private void validateSnapshot(boolean expectSuccess) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream original = System.out;
    try {
        System.setOut(ps);
        String args[] = new String[] { TESTNONCE, "--dir", TMPDIR };
        SnapshotVerifier.main(args);
        ps.flush();
        String reportString = baos.toString("UTF-8");

        System.err.println("Validate Snapshot :"+reportString);

        if (expectSuccess) {
            assertTrue(reportString.startsWith("Snapshot valid\n"));
            System.err.println("Validate Snapshot :" + "Snapshot valid");
        } else {
            assertTrue(reportString.startsWith("Snapshot corrupted\n"));
            System.err.println("Validate Snapshot :" + "Snapshot corrupted");
        }
    } catch (UnsupportedEncodingException e) {
    } finally {
        System.setOut(original);
    }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:26,代码来源:TestSnapshotSaveAndRestorePartitionedTable.java

示例3: toString

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Convert an {@link InputStream} into a {@link String}. Reference the SO below for an interesting
 * performance comparison of various InputStream to String methodologies.
 *
 * @param inputStream An instance of {@link InputStream}.
 *
 * @return A {@link String}
 *
 * @throws IOException If the {@code inputStream} is unable to be read properly.
 * @see "http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string"
 */
private String toString(final InputStream inputStream, final int lengthToRead)
    throws IOException {
  Objects.requireNonNull(inputStream);
  ByteArrayOutputStream result = new ByteArrayOutputStream();

  // Read lengthToRead bytes from the inputStream into the buffer...
  byte[] buffer = new byte[lengthToRead];
  int read = inputStream.read(buffer);
  
  if (read != lengthToRead) {
    throw new IOException(
        "error reading " + lengthToRead + " bytes from stream, only read " + read);
  }
  
  result.write(buffer, 0, lengthToRead);
  return result.toString(StandardCharsets.US_ASCII.name());
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:29,代码来源:OerIA5StringCodec.java

示例4: validateSnapshot

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private void validateSnapshot(boolean expectSuccess) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream original = System.out;
    try {
        System.setOut(ps);
        String args[] = new String[] { TESTNONCE, "--dir", TMPDIR };
        SnapshotVerifier.main(args);
        ps.flush();
        String reportString = baos.toString("UTF-8");

        // System.err.println("Validate Snapshot :"+reportString);

        if (expectSuccess) {
            assertTrue(reportString.startsWith("Snapshot valid\n"));
            System.err.println("Validate Snapshot :" + "Snapshot valid");
        } else {
            assertTrue(reportString.startsWith("Snapshot corrupted\n"));
            System.err.println("Validate Snapshot :" + "Snapshot corrupted");
        }
    } catch (UnsupportedEncodingException e) {
    } finally {
        System.setOut(original);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:26,代码来源:TestYCSBLogicalRecovery.java

示例5: reloadList

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public void reloadList() throws IOException{
	clear();
	AssetInfo info=_AM.locateAsset(new AssetKey(_AM_PATH+"substances.json"));
	if(info!=null){
		InputStream is=info.openStream();
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		byte chunk[]=new byte[1024*1024];
		int readed;
		while((readed=is.read(chunk))!=-1)bos.write(chunk,0,readed);
		String json=bos.toString("UTF-8");
		Map<Object,Object> map=(Map)_JSON.parse(json);
		for(java.util.Map.Entry<Object,Object> e:map.entrySet()){
			Substance s=new Substance();
			s.setSubstancesList(this);
			s.putAll((Map)e.getValue());
			put((String)e.getKey(),s);	
		}
	}else{
		LOGGER.log(Level.FINE,"substances.json not found");
	}
}
 
开发者ID:riccardobl,项目名称:JMELink-SP,代码行数:22,代码来源:SubstancesList.java

示例6: decompressForZip

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * Zip解压数据
 *
 * @param zipStr
 * @return
 */
public static String decompressForZip(String zipStr) {

    if (TextUtils.isEmpty(zipStr)) {
        return "0";
    }
    byte[] t = Base64.decode(zipStr, Base64.DEFAULT);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream in = new ByteArrayInputStream(t);
        ZipInputStream zip = new ZipInputStream(in);
        zip.getNextEntry();
        byte[] buffer = new byte[1024];
        int n = 0;
        while ((n = zip.read(buffer, 0, buffer.length)) > 0) {
            out.write(buffer, 0, n);
        }
        zip.close();
        in.close();
        out.close();
        return out.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "0";
}
 
开发者ID:SailFlorve,项目名称:RunHDU,代码行数:32,代码来源:ZipUtil.java

示例7: gzipUncompressToString

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static String gzipUncompressToString(byte[] b) {
    if (b == null || b.length == 0) {
        return null;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayInputStream in = new ByteArrayInputStream(b);
    try {
        GZIPInputStream gunzip = new GZIPInputStream(in);
        byte[] buffer = new byte[256];
        int n;
        while ((n = gunzip.read(buffer)) >= 0) {
            out.write(buffer, 0, n);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toString();
}
 
开发者ID:zh-h,项目名称:pxclawer,代码行数:19,代码来源:StringUtil.java

示例8: runTool

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private String runTool(Configuration conf, String[] args, boolean success)
    throws Exception {
  ByteArrayOutputStream o = new ByteArrayOutputStream();
  PrintStream out = new PrintStream(o, true);
  try {
    int ret = ToolRunner.run(getTool(out), args);
    assertEquals(success, ret == 0);
    return o.toString();
  } finally {
    o.close();
    out.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:GetGroupsTestBase.java

示例9: BytyToString

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static String BytyToString(InputStream in) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int num = 0;
    while ((num = in.read(buf)) != -1) {
        out.write(buf, 0, buf.length);
    }
    String result = out.toString();
    out.close();
    return result;
}
 
开发者ID:Wan7451,项目名称:mvparms,代码行数:12,代码来源:DataHelper.java

示例10: dump

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private static void dump(ByteArrayBuffer buf, String caption, Map<String, List<String>> headers) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos, true);
    pw.println("---["+caption +"]---");
    if (headers != null) {
        for (Entry<String, List<String>> header : headers.entrySet()) {
            if (header.getValue().isEmpty()) {
                // I don't think this is legal, but let's just dump it,
                // as the point of the dump is to uncover problems.
                pw.println(header.getValue());
            } else {
                for (String value : header.getValue()) {
                    pw.println(header.getKey() + ": " + value);
                }
            }
        }
    }
    if (buf.size() > dump_threshold) {
        byte[] b = buf.getRawData();
        baos.write(b, 0, dump_threshold);
        pw.println();
        pw.println(WsservletMessages.MESSAGE_TOO_LONG(HttpAdapter.class.getName() + ".dumpTreshold"));
    } else {
        buf.writeTo(baos);
    }
    pw.println("--------------------");

    String msg = baos.toString();
    if (dump) {
      System.out.println(msg);
    }
    if (LOGGER.isLoggable(Level.FINER)) {
      LOGGER.log(Level.FINER, msg);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:HttpAdapter.java

示例11: testJsonLdCustomSerializer

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testJsonLdCustomSerializer() throws UnsupportedEncodingException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    service.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.w3.org/ns/anno.jsonld"));
    final String output = out.toString("UTF-8");
    assertTrue(output.contains("\"dcterms:title\":\"A title\""));
    assertTrue(output.contains("\"type\":\"Text\""));
    assertTrue(output.contains("\"@context\":"));
    assertTrue(output.contains("\"@context\":\"http://www.w3.org/ns/anno.jsonld\""));
    assertFalse(output.contains("\"@graph\":"));

    final Graph graph = rdf.createGraph();
    service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), null, JSONLD).forEach(graph::add);
    validateGraph(graph);
}
 
开发者ID:trellis-ldp-archive,项目名称:trellis-io-jena,代码行数:16,代码来源:IOServiceTest.java

示例12: taskResultIndexMapping

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public String taskResultIndexMapping() {
    try (InputStream is = getClass().getResourceAsStream(TASK_RESULT_INDEX_MAPPING_FILE)) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Streams.copy(is, out);
        return out.toString(IOUtils.UTF_8);
    } catch (Exception e) {
        logger.error(
            (Supplier<?>) () -> new ParameterizedMessage(
                "failed to create tasks results index template [{}]", TASK_RESULT_INDEX_MAPPING_FILE), e);
        throw new IllegalStateException("failed to create tasks results index template [" + TASK_RESULT_INDEX_MAPPING_FILE + "]", e);
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TaskResultsService.java

示例13: convertStreamToString

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private String convertStreamToString(File file) throws IOException {
    InputStream is = new FileInputStream(file);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int i = -1;
    while ((i = is.read()) != -1) {
        baos.write(i);
    }
    is.close();
    return baos.toString();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:WsitHandleTask.java

示例14: testToJsonWithTags

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
@Test
public void testToJsonWithTags() throws Exception {
  long epoch = System.currentTimeMillis();
  long value = 1515;
  DataPoint dataPoint = new DataPoint(tagEncodedMetricName.getMetricName(),
      epoch, value, tagEncodedMetricName.getTags());

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  dataPoint.toJson(new PrintStream(out), null);
  String jsonTxt = out.toString();

  DataPoint dp = Util.jsonToDataPoint(jsonTxt);
  assertEquals(dataPoint, dp);
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:15,代码来源:DataPointTest.java

示例15: byteToString

import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
 * 输入流转为 String
 *
 * @param in InputStream
 * @return String
 */
public static String byteToString(InputStream in) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int num = 0;
    while ((num = in.read(buf)) != -1) {
        out.write(buf, 0, buf.length);
    }
    String result = out.toString();
    out.close();
    return result;
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:18,代码来源:DataHelper.java


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