Example usage for org.apache.commons.io IOUtils toInputStream

List of usage examples for org.apache.commons.io IOUtils toInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils toInputStream.

Prototype

public static InputStream toInputStream(String input) 

Source Link

Document

Convert the specified string to an input stream, encoded as bytes using the default character encoding of the platform.

Usage

From source file:com.collective.celos.ci.testing.fixtures.convert.FixDirRecursiveConverterTest.java

private FixDir createDirWithSubdirsAndFile(String fileContent) {
    FixDir dir1 = getFixDirWithTwoFiles1(fileContent);
    FixDir dir2 = getFixDirWithTwoFiles1(fileContent);
    InputStream inputStream2 = IOUtils.toInputStream(fileContent);
    FixFile file = new FixFile(inputStream2);

    Map<String, FixFsObject> content = Maps.newHashMap();
    content.put("dir1", dir1);
    content.put("dir2", dir2);
    content.put("file", file);
    return new FixDir(content);
}

From source file:mitm.common.util.NameValueLineIteratorTest.java

@Test
public void testNameValueLineIteratorNextTooMany() throws IOException {
    String data = "test=123";

    NameValueLineIterator.Entry entry;/*w  w  w .  j  a va  2s. c om*/

    Iterator<NameValueLineIterator.Entry> it = new NameValueLineIterator(IOUtils.toInputStream(data));

    assertTrue(it.hasNext());
    entry = it.next();
    assertEquals("test", entry.getName());
    assertEquals("123", entry.getValue());

    // should throw NoSuchElementException
    try {
        entry = it.next();

        fail();
    } catch (NoSuchElementException e) {
        // expected
    }
}

From source file:es.us.isa.sedl.core.analysis.datasetspecification.AbstractDatasetSpecificationTest.java

public void testApplyWithGrouping() {
    try {/*from w  ww.  jav a2s  .c om*/
        CSVLoader csvLoader = new CSVLoader(Boolean.TRUE);
        String initialDatasetContent = "Sex;Height" + NEW_LINE + "man;1.82" + NEW_LINE + "woman;1.63";
        DataSet initialDataset = csvLoader.load(IOUtils.toInputStream(initialDatasetContent), "csv");
        // TESTING PROJECTION APPLICATION:
        String expectedResultContent = "Height|Sex=man;Height|Sex=woman" + NEW_LINE + "1.82;1.63";
        DataSet expectedResult = csvLoader.load(IOUtils.toInputStream(expectedResultContent), "csv");
        DatasetSpecification datasetSpecification = new DatasetSpecification();
        GroupingProjection gp = new GroupingProjection();
        gp.getProjectedVariables().add("Sex");
        datasetSpecification.getProjections().add(gp);
        DataSet result = datasetSpecification.apply(initialDataset);
        assertEquals(expectedResult, result);
    } catch (IOException ex) {
        Logger.getLogger(AbstractDatasetSpecificationTest.class.getName()).log(java.util.logging.Level.SEVERE,
                null, ex);
        fail(ex.getMessage());
    }
}

From source file:com.github.restdriver.clientdriver.unit.ClientDriverResponseTest.java

@SuppressWarnings("deprecation")
@Test/*from  w w w  .  j  a v  a 2 s.c o  m*/
public void creatingEmptyResponseGivesNoContentType() {

    assertThat(new ClientDriverResponse().getContentType(), is(nullValue()));
    assertThat(new ClientDriverResponse((String) null).getContentType(), is(nullValue()));
    assertThat(new ClientDriverResponse("").getContentType(), is(nullValue()));
    assertThat(new ClientDriverResponse((InputStream) null, null).getContentType(), is(nullValue()));
    assertThat(new ClientDriverResponse(IOUtils.toInputStream(""), null).getContentType(), is(nullValue()));

}

From source file:com.github.restdriver.clientdriver.unit.ClientDriverHandlerTest.java

/**
 * with no expectations set, and a request made, the handler throws an error upon verification
 *//* w w  w.  j  ava 2  s.  c  o  m*/
@Test
public void testUnexpectedRequest() throws IOException, ServletException {

    Request mockRequest = mock(Request.class);
    HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);

    when(mockHttpRequest.getMethod()).thenReturn("POST");
    when(mockHttpRequest.getPathInfo()).thenReturn("yarr");
    when(mockHttpRequest.getQueryString()).thenReturn("gooo=gredge");
    when(mockHttpRequest.getInputStream()).thenReturn(new DummyServletInputStream(IOUtils.toInputStream("")));

    try {
        sut.handle("", mockRequest, mockHttpRequest, mockHttpResponse);
        Assert.fail();
    } catch (ClientDriverFailedExpectationException e) {
        assertThat(e.getMessage(), containsString("1 unexpected request(s):"));
        assertThat(e.getMessage(), containsString("POST yarr; PARAMS: [gooo=[gredge]];"));
    }
}

From source file:com.ibm.wala.cast.js.nodejs.NodejsRequiredSourceModule.java

@Override
public InputStream getInputStream() {
    String moduleSource = null;//from ww w  .j  a  v  a2  s  .  co m
    try (final InputStream inputStream = super.getInputStream()) {
        moduleSource = IOUtils.toString(inputStream);
    } catch (IOException e) {
        Assertions.UNREACHABLE(e.getMessage());
    }

    String wrapperSource = null;
    String ext = FilenameUtils.getExtension(getFile().toString()).toLowerCase();
    if (ext.equals("js")) {
        // JS file -> use module wrapper
        wrapperSource = MODULE_WRAPPER_SOURCE;
    } else if (ext.equals("json")) {
        // JSON file -> use JSON wrapper
        wrapperSource = JSON_WRAPPER_SOURCE;
    } else {
        // No clue -> try module wrapper
        System.err.println("NodejsRequiredSourceModule: Unsupported file type (" + ext + "), continue anyway.");
        wrapperSource = MODULE_WRAPPER_SOURCE;
    }

    String wrappedModuleSource = wrapperSource.replace(FILENAME_PLACEHOLDER, getFile().getName())
            .replace(DIRNAME_PLACEHOLDER, getFile().getParent().toString())
            .replace(CODE_PLACEHOLDER, moduleSource);

    return IOUtils.toInputStream(wrappedModuleSource);
}

From source file:com.nanocrawler.feedfinder.RSSFeedCrawler.java

public boolean isRSSFeed(String page) {
    boolean isFeed = false;
    try {/*from  w w w . j a va 2 s  .c om*/
        if (page.length() > 0) {
            page = page.trim();
            page = c.cleanFeedString(page);
            FeedFormat fformat = FeedFormatDetector.getFormat(IOUtils.toInputStream(page.trim()), false);
            if (fformat != FeedFormat.UNKNOWN) {
                isFeed = true;
            }
        }
    } catch (Exception ex) {
    }
    return isFeed;
}

From source file:de.hybris.platform.addonsupport.setup.impl.DefaultSetupImpexAddOnService.java

protected InputStream getMergedInputStream(final Map<String, Object> macroParameters,
        final InputStream fileStream) {

    if (macroParameters != null && !macroParameters.isEmpty()) {
        final String header = buildMacroHeader(macroParameters);
        return new SequenceInputStream(IOUtils.toInputStream(header), fileStream);
    } else {//  ww w .  j a va 2  s .  co m
        return fileStream;
    }
}

From source file:com.lightbox.android.webservices.processors.JacksonProcessor.java

@SuppressWarnings("unchecked")
public static HashMap<String, Object> jsonToMap(String json) throws ParsingException {
    HashMap<String, Object> map = null;
    // To Map/*from   www. ja  v  a 2s  . c o  m*/
    if (json != null) {
        @SuppressWarnings("rawtypes")
        JacksonProcessor<HashMap> processor = new JacksonProcessor<HashMap>();
        map = processor.parse(HashMap.class, IOUtils.toInputStream(json));
    }
    return map;
}

From source file:com.msopentech.odatajclient.engine.performance.BasicPerfTest.java

@Test
public void readAtomViaLowerlevelLibs() throws ParserConfigurationException, SAXException, IOException {
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = factory.newDocumentBuilder();

    final Document entry = builder.parse(IOUtils.toInputStream(input.get(ODataPubFormat.ATOM)));
    assertNotNull(entry);//from  ww w.j  ava2 s.c o m
    entry.getDocumentElement().normalize();
}