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


Java IOUtils.toInputStream方法代码示例

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


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

示例1: getMapFromXML

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static Map<String,Object> getMapFromXML(String xmlString) throws ParserConfigurationException, IOException, SAXException {

        //这里用Dom的方式解析回包的最主要目的是防止API新增回包字段
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputStream is =  IOUtils.toInputStream(xmlString);
        Document document = builder.parse(is);
        //获取到document里面的全部结点
        NodeList allNodes = document.getFirstChild().getChildNodes();
        Node node;
        Map<String, Object> map = new HashMap<String, Object>();
        int i=0;
        while (i < allNodes.getLength()) {
            node = allNodes.item(i);
            if(node instanceof Element){
                map.put(node.getNodeName(),node.getTextContent());
            }
            i++;
        }
        return map;

    }
 
开发者ID:1991wangliang,项目名称:pay,代码行数:23,代码来源:XMLParser.java

示例2: saveReportFile

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void saveReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String file=req.getParameter("file");
	file=ReportUtils.decodeFileName(file);
	String content=req.getParameter("content");
	ReportProvider targetReportProvider=null;
	for(ReportProvider provider:reportProviders){
		if(file.startsWith(provider.getPrefix())){
			targetReportProvider=provider;
			break;
		}
	}
	if(targetReportProvider==null){
		throw new ReportDesignException("File ["+file+"] not found available report provider.");
	}
	targetReportProvider.saveReport(file, content);
	InputStream inputStream=IOUtils.toInputStream(content,"utf-8");
	ReportDefinition reportDef=reportParser.parse(inputStream, file);
	reportRender.rebuildReportDefinition(reportDef);
	CacheUtils.cacheReportDefinition(file, reportDef);
	IOUtils.closeQuietly(inputStream);
}
 
开发者ID:youseries,项目名称:ureport,代码行数:22,代码来源:DesignerServletAction.java

示例3: mapper_boundWithMultipleNamedAndOneUnnamedInputStreams_shouldReadCorrespondingStreams

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void mapper_boundWithMultipleNamedAndOneUnnamedInputStreams_shouldReadCorrespondingStreams() {
	String streamName = "foo";
	String secondStreamName = "bar";
	stream = new CarmlStream(streamName);
	InputStream inputStream = IOUtils.toInputStream(input);
	InputStream secondInputStream = IOUtils.toInputStream(secondInput);
	String unnamedInput = "unnamed test input";
	InputStream unnamedInputStream = IOUtils.toInputStream(unnamedInput);
	mapper.bindInputStream(streamName, inputStream);
	mapper.bindInputStream(secondStreamName, secondInputStream);
	mapper.bindInputStream(unnamedInputStream);
	assertThat(mapper.getSourceManager().getSource(streamName), is(input));
	assertThat(mapper.getSourceManager().getSource(secondStreamName), is(secondInput));
	assertThat(mapper.getSourceManager().getSource(RmlMapper.DEFAULT_STREAM_NAME), is(unnamedInput));
}
 
开发者ID:carml,项目名称:carml,代码行数:17,代码来源:RmlMapperTest.java

示例4: run_on_valid_response

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void run_on_valid_response() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/service1" + DEFAULT_URL);
    RequestContext context = RequestContext.getCurrentContext();
    context.setRequest(request);

    MockHttpServletResponse response = new MockHttpServletResponse();
    context.setResponseGZipped(false);
    context.setResponse(response);

    InputStream in = IOUtils.toInputStream("{\"basePath\":\"/\"}", StandardCharsets.UTF_8);
    context.setResponseDataStream(in);

    filter.run();

    assertEquals("UTF-8", response.getCharacterEncoding());
    assertEquals("{\"basePath\":\"/service1\"}", context.getResponseBody());
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:19,代码来源:SwaggerBasePathRewritingFilterTest.java

示例5: testGetVersion_WithMockedManifest_ReturnsValidVersion

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void testGetVersion_WithMockedManifest_ReturnsValidVersion() throws IOException {
    //  Arrange.
    PowerMockito.mockStatic(VersionUtil.class);
    PowerMockito.when(VersionUtil.getVersion()).thenCallRealMethod();
    PowerMockito.when(VersionUtil.class.getPackage()).thenReturn(this.aPackage);
    PowerMockito.when(VersionUtil.class.getClassLoader()).thenReturn(this.classLoader);
    PowerMockito.when(this.classLoader.findResource(Matchers.anyString())).thenReturn(this.mockedUrl);
    InputStream stubInputStream = IOUtils.toInputStream(this.MANIFEST_CONTENT, Charset.defaultCharset());
    PowerMockito.when(this.mockedUrl.openStream()).thenReturn(stubInputStream);
    PowerMockito.when(this.aPackage.getImplementationVersion()).thenReturn("1.0.0");

    // Act.
    Version version = VersionUtil.getVersion();

    // Assert.
    Assert.assertTrue("11" == version.getBuild());
    Assert.assertEquals("1476885882", version.getBuildTime());
    Assert.assertTrue(1 == version.getMajor());
    Assert.assertTrue(2 == version.getMinor());
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:21,代码来源:VersionUtilTest.java

示例6: testGetPidByProcessName_WithImproperData_ReturnsNothing

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testGetPidByProcessName_WithImproperData_ReturnsNothing() throws IOException, InterruptedException {
    // Arrange.
    InputStream stubInputStream = IOUtils.toInputStream(
            " PID TTY STAT TIME COMMAND\n 9990 ? Ss 0:07 /test/java\n " + this.oldProcessId + " ? Ss 0:07 /osc/java",
            Charset.defaultCharset());

    PowerMockito.when(this.processMock.getInputStream()).thenReturn(stubInputStream);
    PowerMockito.when(this.runtimeMock.exec(this.linuxProcessExec)).thenReturn(this.processMock);

    Mockito.when(Runtime.getRuntime()).thenReturn(this.runtimeMock);

    // Act.
    String foundPid = ServerUtil.getPidByProcessName("/osc/test");

    // Assert.
    Assert.assertNull(foundPid);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:19,代码来源:ServerUtilTest.java

示例7: send

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void send(String senderAddress, String senderName, String recipient, String content) {
    if (StringUtils.isBlank(senderAddress)) {
        throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
                "You must set a value for notifications to work");
    }

    if (StringUtils.isBlank(content)) {
        throw new InternalServerError("Notification content is empty");
    }

    try {
        InternetAddress sender = new InternetAddress(senderAddress, senderName);
        MimeMessage msg = new MimeMessage(session, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
        msg.setHeader("X-Mailer", "mxisd"); // FIXME set version
        msg.setSentDate(new Date());
        msg.setFrom(sender);
        msg.setRecipients(Message.RecipientType.TO, recipient);
        msg.saveChanges();

        log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
        SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
        transport.setStartTLS(cfg.getTls() > 0);
        transport.setRequireStartTLS(cfg.getTls() > 1);

        log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort());
        transport.connect(cfg.getHost(), cfg.getPort(), cfg.getLogin(), cfg.getPassword());
        try {
            transport.sendMessage(msg, InternetAddress.parse(recipient));
            log.info("Invite to {} was sent", recipient);
        } finally {
            transport.close();
        }
    } catch (UnsupportedEncodingException | MessagingException e) {
        throw new RuntimeException("Unable to send e-mail invite to " + recipient, e);
    }
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:38,代码来源:EmailSmtpConnector.java

示例8: sync

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void sync() throws IOException {
	InputStream csv = IOUtils.toInputStream(sgc2csv(null).toString(), ENCODING_P2S);
	AppliConfig appliConfig = AppliConfig.findAppliConfigByKey("P2S_EXPORT_CSV_FILE_NAME");
	String filename = appliConfig.getValue();
	Date date = new Date();
	p2sVfsAccessService.putFile(null, date.getTime() + "_" + filename, csv, false);
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:8,代码来源:CsvExportP2sService.java

示例9: readSuccessful

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void readSuccessful() throws IOException {
    String path = "file";
    File file = new File(sourceDir, path);
    InputStream inputStream = IOUtils.toInputStream(fileContent, "UTF-8");
    FileUtils.copyInputStreamToFile(inputStream, file);
    String result = access.read(path);

    assertNotNull(result);

    assertEquals(fileContent, result);
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:13,代码来源:PluginFileAccessTest.java

示例10: sync

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void sync(List<String> eppns) throws IOException {
	InputStream csv = IOUtils.toInputStream(sgc2csv(eppns).toString(), ENCODING_TIL);
	AppliConfig appliConfig = AppliConfig.findAppliConfigByKey("TIL_EXPORT_CSV_FILE_NAME");
	String filename = appliConfig.getValue();
	tilVfsAccessService.putFile(null, filename, csv, true);
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:8,代码来源:CsvExportTilService.java

示例11: mapper_boundWithMultipleNamedInputStreams_shouldReadLastBoundStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void mapper_boundWithMultipleNamedInputStreams_shouldReadLastBoundStream() {
	String streamName = "foo";
	String secondStreamName = "bar";
	InputStream inputStream = IOUtils.toInputStream(input);
	InputStream secondInputStream = IOUtils.toInputStream(secondInput);
	mapper.bindInputStream(streamName, inputStream);
	assertThat(mapper.getSourceManager().getSource(streamName), is(input));
	mapper.bindInputStream(secondStreamName, secondInputStream);
	assertThat(mapper.getSourceManager().getSource(secondStreamName), is(secondInput));
}
 
开发者ID:carml,项目名称:carml,代码行数:12,代码来源:RmlMapperTest.java

示例12: mapper_boundWithMultipleUnnamedInputStreams_shouldReadLastBoundStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void mapper_boundWithMultipleUnnamedInputStreams_shouldReadLastBoundStream() {
	InputStream inputStream = IOUtils.toInputStream(input);
	InputStream secondInputStream = IOUtils.toInputStream(secondInput);
	mapper.bindInputStream(inputStream);
	assertThat(mapper.getSourceManager().getSource(RmlMapper.DEFAULT_STREAM_NAME), is(input));
	mapper.bindInputStream(secondInputStream);
	assertThat(mapper.getSourceManager().getSource(RmlMapper.DEFAULT_STREAM_NAME), is(secondInput));
}
 
开发者ID:carml,项目名称:carml,代码行数:10,代码来源:RmlMapperTest.java

示例13: mapper_boundWithMultipleNamedInputStreams_shouldReadCorrespondingStreams

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void mapper_boundWithMultipleNamedInputStreams_shouldReadCorrespondingStreams() {
	String streamName = "foo";
	String secondStreamName = "bar";
	stream = new CarmlStream(streamName);
	InputStream inputStream = IOUtils.toInputStream(input);
	String secondInput = "second test input";
	InputStream secondInputStream = IOUtils.toInputStream(secondInput);
	mapper.bindInputStream(streamName, inputStream);
	mapper.bindInputStream(secondStreamName, secondInputStream);
	assertThat(mapper.getSourceManager().getSource(streamName), is(input));
	assertThat(mapper.getSourceManager().getSource(secondStreamName), is(secondInput));
}
 
开发者ID:carml,项目名称:carml,代码行数:14,代码来源:RmlMapperTest.java

示例14: mapper_boundWithNamedInputStream_shouldReadCorrespondingInputStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void mapper_boundWithNamedInputStream_shouldReadCorrespondingInputStream() {
	String streamName = "foo";
	stream = new CarmlStream(streamName);
	InputStream inputStream = IOUtils.toInputStream(input);
	mapper.bindInputStream(streamName, inputStream);
	assertThat(mapper.getSourceManager().getSource(streamName), is(input));
}
 
开发者ID:carml,项目名称:carml,代码行数:9,代码来源:RmlMapperTest.java

示例15: paramAsInputStream

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public InputStream paramAsInputStream(String key) {
	return IOUtils.toInputStream(param(key));
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:5,代码来源:MockRequest.java


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