本文整理汇总了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();
}
}
}
示例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);
}
}
示例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));
}
示例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) };
}
示例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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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());
}
示例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");
}
示例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);
}
}
示例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");
}