List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input, String encoding) throws IOException
From source file:car_counter.storage.sqlite.TestSqliteStorage.java
@Before public void setUp() throws Exception { dbFile = Files.createTempFile("test", ".db"); String iniValue = String.format("[Storage]\n" + "implementation = sqlite\n" + "database = %s\n", dbFile); try (InputStream stream = IOUtils.toInputStream(iniValue, StandardCharsets.UTF_8)) { ini = new Wini(stream); }//from ww w . j av a 2 s .c o m }
From source file:com.ibm.rpe.web.template.ui.servlet.SaveTemplateLayout.java
@GET @Path("/savelayout") @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public Response saveTemplateLayout(@Context HttpServletRequest request, @QueryParam("layoutjson") String savedJson, @QueryParam("title") String title) { try {//from ww w .jav a 2s . co m if (title == null) { title = UUID.randomUUID().toString() + ".json"; } else { title += ".json"; } return Utils.downloadResponse(IOUtils.toInputStream(savedJson, "UTF-8"), title); } catch (IOException e) { e.printStackTrace(); Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getLocalizedMessage()).build(); } return null; }
From source file:de.knowwe.selesup.sofa.ArticleSofa.java
@Override public InputStream getInputStream() throws IOException { return IOUtils.toInputStream(article.getText(), Charset.forName("UTF-8")); }
From source file:eu.freme.eservices.pipelines.core.Conversion.java
public String htmlToNif(final String html) throws IOException, ConversionException { try (InputStream in = IOUtils.toInputStream(html, StandardCharsets.UTF_8)) { try (Reader reader = eInternationalizationApi.convertToTurtleWithMarkups(in, EInternationalizationAPI.MIME_TYPE_HTML)) { skeletonNIF = IOUtils.toString(reader); }//from ww w . j av a 2s .co m } try (InputStream in = IOUtils.toInputStream(html, StandardCharsets.UTF_8)) { try (Reader reader = eInternationalizationApi.convertToTurtle(in, EInternationalizationAPI.MIME_TYPE_HTML)) { return IOUtils.toString(reader); } } }
From source file:de.shadowhunt.subversion.internal.ResourcePropertyUtilsTest.java
@Test public void testEscapedInputStream_emptyTagInHierarchy() throws Exception { final String xml = "<A><svn:B><C:foo:bar/></svn:B></A>"; final String expected = "<A><svn:B><C:foo" + MARKER + "bar/></svn:B></A>"; final InputStream stream = IOUtils.toInputStream(xml, ResourcePropertyUtils.UTF8); final InputStream escapedStream = ResourcePropertyUtils.escapedInputStream(stream); final String escapedXml = IOUtils.toString(escapedStream, ResourcePropertyUtils.UTF8); Assert.assertEquals(expected, escapedXml); }
From source file:ch.cyberduck.core.s3.S3SessionCredentialsRetrieverTest.java
@Test public void testParse() throws Exception { final AWSCredentials c = new S3SessionCredentialsRetriever(new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DisabledTranscriptListener(), "http://169.254.169.254/latest/meta-data/iam/security-credentials/s3access") .parse(IOUtils.toInputStream("{\n" + " \"Code\" : \"Success\",\n" + " \"LastUpdated\" : \"2012-04-26T16:39:16Z\",\n" + " \"Type\" : \"AWS-HMAC\",\n" + " \"AccessKeyId\" : \"AKIAIOSFODNN7EXAMPLE\",\n" + " \"SecretAccessKey\" : \"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\",\n" + " \"Token\" : \"token\",\n" + " \"Expiration\" : \"2012-04-27T22:39:16Z\"\n" + "}", Charset.defaultCharset())); assertEquals("AKIAIOSFODNN7EXAMPLE", c.getAccessKey()); assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", c.getSecretKey()); assertEquals("token", ((AWSSessionCredentials) c).getSessionToken()); }
From source file:com.peadargrant.filecheck.core.checks.TextEvaluationTest.java
@Before public void setUp() throws IOException { instance = new TextEvaluation(); input = IOUtils.toInputStream(SOURCE_TEXT, "UTF-8"); result = Mockito.mock(CheckResult.class); parameters = new ArrayList<>(); }
From source file:com.github.sleroy.junit.mail.server.MailListenerTest.java
@Test public void testDeliver() throws Exception { MailSaverInterface mailSaver = Mockito.mock(MailSaverInterface.class); MailListener mailListener = new MailListener(mailSaver); // WHEN deliver a new mail mailListener.deliver("me@mail.org", "recipient", IOUtils.toInputStream("test", "UTF-8")); // THEN it invokes the mail saver Mockito.verify(mailSaver, Mockito.times(1)).saveEmailAndNotify(Mockito.eq("me@mail.org"), Mockito.eq("recipient"), Mockito.any(InputStream.class)); }
From source file:cop.raml.mocks.FileObjectMock.java
@Override public InputStream openInputStream() throws IOException { return data != null ? IOUtils.toInputStream(data, StandardCharsets.UTF_8) : null; }
From source file:com.elsevier.xml.XQueryProcessor.java
/** * Apply the xqueryExpression to the specified string and return a * serialized response.//from w ww . j av a 2 s. com * * @param content * String to which the xqueryExpression will be applied * @param xqueryExpression * XQuery expression to apply to the content * * @return Serialized response from the evaluation. If an error, the response will be "<error/>". */ public static String evaluateString(String content, String xqueryExpression) { try { return evaluate(new StreamSource(IOUtils.toInputStream(content, CharEncoding.UTF_8)), xqueryExpression); } catch (IOException e) { log.error("Problems processing the content. " + e.getMessage(), e); return "<error/>"; } }