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


Java IOUtils.toString方法代码示例

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


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

示例1: testIntegrityUnicityError

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * @see ExceptionMapperResource#throwDataIntegrityUnicityException()
 */
@Test
public void testIntegrityUnicityError() throws IOException {
	final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/integrity-unicity");
	HttpResponse response = null;
	try {
		response = httpclient.execute(httpdelete);
		Assert.assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
		final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
		final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
		Assert.assertEquals("integrity-unicity", result.get("code"));
		Assert.assertNull(result.get("cause"));
		Assert.assertEquals("2003/PRIMARY", result.get("message"));
	} finally {
		if (response != null) {
			response.getEntity().getContent().close();
		}
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:ExceptionMapperIT.java

示例2: ReactViewResolver

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public ReactViewResolver()
{
    final ClassLoader classLoader = this.getClass().getClassLoader();

    try
    {
        template = new BaseTemplate(
            IOUtils.toString(
                classLoader.getResourceAsStream(TEMPLATE_RESOURCE),
                BaseTemplate.UTF_8
            )
        );
    }
    catch (IOException e)
    {
        throw new ExampleException(e);
    }
}
 
开发者ID:fforw,项目名称:spring-react-example,代码行数:19,代码来源:ReactViewResolver.java

示例3: doPost

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
	response.setContentType("application/json");
	response.setCharacterEncoding("utf-8");

	PrintWriter out = response.getWriter();

	String rawContent = IOUtils.toString(request.getReader());
	log.debug(String.format("request content: %s", rawContent));

	out.print(goodsDAO.findById(1));
}
 
开发者ID:MsBuggy,项目名称:AnyMall,代码行数:14,代码来源:GoodsCtrl.java

示例4: read

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * Returns the content read form content-source.
 * @return read {@link Content}
 */
@Override
public Content[] read(final FetchHistory lastFetch) {

	final CloseableHttpClient httpClient = HttpClients.createDefault();
	final HttpGet httpget = new HttpGet(contentSource.getUrl());
	final HttpContext context = new BasicHttpContext();

	CloseableHttpResponse response = null;
	String stringRead = null;

	try {
		try {
			LOGGER.info("Loading uri: " + httpget.getURI());
			response = httpClient.execute(httpget, context);
			final HttpEntity entity = response.getEntity();

			if (entity != null) {
				stringRead = IOUtils.toString(entity.getContent());
				LOGGER.info("Read {} bytes from: {}", stringRead.getBytes().length, httpget.getURI());
			}

		} finally {
			CloseUtil.close(response);
			CloseUtil.close(httpClient);
		}

	} catch (final Exception e) {
		LOGGER.warn("Error occurred while reading text document: " + contentSource.getUrl());
	}

	return new Content[] { createContentObject(stringRead) };
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:37,代码来源:TxtContentReader.java

示例5: provide

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public Resource provide(String path,String version) {
	String newpath=path.substring(4,path.length());
	InputStream inputStream=null;
	try {
		if(StringUtils.isEmpty(version) || version.equals("LATEST")){
			inputStream=repositoryService.readFile(newpath,null);											
		}else{
			inputStream=repositoryService.readFile(newpath,version);														
		}
		String content=IOUtils.toString(inputStream,"utf-8");
		IOUtils.closeQuietly(inputStream);
		return new Resource(content,path);
	} catch (Exception e) {
		throw new RuleException(e);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:18,代码来源:RepositoryResourceProvider.java

示例6: quandoErroPojoDeveSerGeradoCorretamente

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void quandoErroPojoDeveSerGeradoCorretamente() throws IOException {
  String xmlTest = IOUtils
      .toString(getClass().getClassLoader().getResourceAsStream("erroConsultarLoteRpsResposta.xml"));

  ConsultarLoteRpsResposta pojo = ConsultarLoteRpsResposta.toPojo(xmlTest);
  assertNotNull(pojo.getListaMensagemRetornoLote());

}
 
开发者ID:pablopdomingos,项目名称:nfse,代码行数:10,代码来源:GerarLoteRpsRespostaTest.java

示例7: addUaaSpecification

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@SneakyThrows
private void addUaaSpecification(String tenantName) {
    String specificationName = applicationProperties.getTenantPropertiesName();
    InputStream in = new ClassPathResource(Constants.DEFAULT_CONFIG_PATH).getInputStream();
    String specification = IOUtils.toString(in, UTF_8);
    tenantConfigRepository.updateConfig(tenantName, "/" + specificationName, specification);
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:8,代码来源:TenantService.java

示例8: xmlDeveSerGeradoCorretamente

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void xmlDeveSerGeradoCorretamente() throws IOException{
  String xmlTest = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("loteRpsConsultaSituacao.xml"));
  LoteRpsConsultaSituacao consultaSituacaoLote = new LoteRpsConsultaSituacao("AP1057893n16X103sfhF4RPm", FabricaDeObjetosFake.getRpsPrestador());
  String xml = consultaSituacaoLote.converterParaXml();
  
  Assert.assertEquals(xml, xmlTest);
}
 
开发者ID:pablopdomingos,项目名称:nfse,代码行数:9,代码来源:LoteRpsConsultaSituacaoTest.java

示例9: loadResourceSecurityConfigs

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{
	List<UserPermission> configs=new ArrayList<UserPermission>();
	String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
	Node rootNode=getRootNode();
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("user-permission")) {
			continue;
		}
		UserPermission userResource=new UserPermission();
		userResource.setUsername(element.attributeValue("username"));
		userResource.setProjectConfigs(parseProjectConfigs(element));
		configs.add(userResource);
	}
	return configs;
}
 
开发者ID:youseries,项目名称:urule,代码行数:29,代码来源:RepositoryServiceImpl.java

示例10: processRequestParams

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public Map<String, Object> processRequestParams(IWebMvc owner, RequestMeta requestMeta) throws Exception {
    Map<String, Object> _params = new HashMap<String, Object>();
    //
    if (!requestMeta.getMethodParamNames().isEmpty()) {
        String _protocol = IOUtils.toString(WebContext.getRequest().getInputStream(), owner.getModuleCfg().getDefaultCharsetEncoding());
        if (StringUtils.isNotBlank(_protocol)) {
            WxPayNotifyResponse _response = WxPayNotifyResponse.bind(_protocol);
            _params.put(requestMeta.getMethodParamNames().get(0), _response);
        }
    }
    return _params;
}
 
开发者ID:suninformation,项目名称:ymate-payment-v2,代码行数:13,代码来源:WxPayRequestProcessor.java

示例11: initTemplateFile

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void initTemplateFile() {
    if (templateFile == null) {
        try {
            templateFile = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE_FILE), StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Could not read widget tempalte file", e);
        }
    }
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:10,代码来源:ClientJsFacadeImpl.java

示例12: testResetFileInputStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testResetFileInputStream() throws IOException {
    ResettableInputStream is = new ResettableInputStream(
            new FileInputStream(file));
    assertTrue(is.markSupported());
    final String content = IOUtils.toString(is);
    is.reset();
    final String content2 = IOUtils.toString(is);
    assertTrue(content.length() == 100);
    assertEquals(content, content2);
    is.close();
    assertNull(is.getFile());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:14,代码来源:ResettableInputStreamTest.java

示例13: testInputStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
void testInputStream() throws IOException {
	String content = IOUtils.toString(source.toInputStream(), StandardCharsets.UTF_8);
	assertWithMessage("stream content was not as expected")
			.that(content).isEqualTo("hello, world");
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:7,代码来源:PathSourceTest.java

示例14: getAllQuery

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private String getAllQuery() {
    URL queryLoc = getClass().getResource(getClass().getSimpleName() + "_getAll.sql");
    try {
        return IOUtils.toString(queryLoc, "UTF-8");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:cloudwall,项目名称:libcwfincore,代码行数:9,代码来源:JdbiProductEntityDao.java

示例15: loadJson

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
String loadJson(String name) throws Exception {
    return IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream((name + ".json")), "UTF-8");
}
 
开发者ID:gdl-lang,项目名称:gdl2,代码行数:4,代码来源:TestCommon.java


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