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, String encoding) throws IOException 

Source Link

Document

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

Usage

From source file:com.fishcart.delivery.service.OrderInformer.java

@RequestMapping(value = "/orderhistory", method = { RequestMethod.POST, RequestMethod.GET }, produces = {
        "application/text" })
public void getOrderHistory(@RequestParam(value = "date") String date, HttpServletResponse response)
        throws IOException {
    String data = generator.getOrderHistory(date);
    response.setHeader("Content-Disposition", "attachment; filename=report.csv");
    IOUtils.copy(IOUtils.toInputStream(data, "UTF-8"), response.getOutputStream());
    response.flushBuffer();/*www . ja v  a  2 s  .c o m*/
}

From source file:com.smartling.cms.gateway.client.upload.HtmlUpload.java

public void setBody(String value) throws IOException {
    Validate.notNull(value);
    setContentStream(IOUtils.toInputStream(value, CharEncoding.UTF_8));
}

From source file:com.romeikat.datamessie.core.base.util.StringUtil.java

public String removeLineSeparators(final String s) {
    if (s == null) {
        return null;
    }//  w w w  .  j  a va2s .c  o m

    try {
        final StringBuilder sb = new StringBuilder();
        final InputStream is = IOUtils.toInputStream(s, StandardCharsets.UTF_8);
        final LineIterator it = IOUtils.lineIterator(is, StandardCharsets.UTF_8);
        while (it.hasNext()) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(it.nextLine());
        }
        IOUtils.closeQuietly(is);
        return sb.toString();
    } catch (final IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.elsevier.xml.XSLTProcessor.java

/**
 * Transform the content using the specified stylesheet.
 * /* w w  w  .  ja va  2 s .c  om*/
 * @param stylesheetName name of the stylesheet (that was set in init)
 * @param content the xml to be transformed
 * @return transformed content
 */
public static String transform(String stylesheetName, String content) {

    try {

        // Get the stylesheet from the cache
        String stylesheet = stylesheetMap.get(stylesheetName);

        if (stylesheet == null) {
            log.error("Problems finding the stylesheet.  STYLESHEET_NAME: " + stylesheetName);
            return "</error>";
        }

        StreamSource stylesheetSource = new StreamSource(IOUtils.toInputStream(stylesheet, CharEncoding.UTF_8));

        // Create streamsource for the content
        StreamSource contentSource = new StreamSource(IOUtils.toInputStream(content, CharEncoding.UTF_8));

        // Apply transformation
        return transform(contentSource, stylesheetSource);

    } catch (IOException e) {

        log.error("Problems transforming the content.  STYLESHEET_NAME: " + stylesheetName + "  "
                + e.getMessage(), e);
        return "</error>";

    }

}

From source file:at.porscheinformatik.common.spring.web.extended.template.velocity.ExpressionHandlerMacroResourceLoader.java

@Override
public InputStream getResourceStream(String source) throws ResourceNotFoundException {
    if (MACRO_LIBRARY_FILE.equals(source)) {
        return IOUtils.toInputStream(buildMacros(), Charset.forName("UTF-8"));
    } else {//from   ww  w.j  a va2s  .co  m
        return null;
    }
}

From source file:com.temenos.useragent.generic.internal.NullEntityWrapper.java

@Override
public InputStream getContent() {
    try {/*ww  w  . j ava  2 s. c o  m*/
        return IOUtils.toInputStream("", "UTF-8");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.uzk.hki.da.metadata.XsltEDMGeneratorTests.java

@Before
public void setUp() throws IOException {
    String content = FileUtils.readFileToString(edmSourceFile, Charset.forName("UTF-8"));
    edmInputStream = IOUtils.toInputStream(content, "utf-8");
}

From source file:com.elsevier.xml.XPathProcessor.java

/**
 * Filter the xpathExpression to the specified string.
 * // ww  w  .j  a  v a  2  s . c  om
 * @param content
 *            String to which the xpathExpression will be applied
 * @param xpathExpression
 *            XPath expression to apply to the content
 * @return TRUE if the xpathExpression evaluates to true, FALSE otherwise
 */
public static boolean filterString(String content, String xpathExpression) {

    try {

        return filter(new StreamSource(IOUtils.toInputStream(content, CharEncoding.UTF_8)), xpathExpression);

    } catch (IOException e) {

        log.error("Problems processing the content.  " + e.getMessage(), e);
        return false;

    }

}

From source file:br.com.autonomiccs.autonomic.plugin.common.utils.ShellCommandUtilsTest.java

@Test
public void executeCommandTest() throws IOException, InterruptedException {
    Process processMock = Mockito.mock(Process.class);
    Runtime runtimeMock = configureAndGetRuntimeMock();

    String commandOutput = "TEST";
    InputStream input = IOUtils.toInputStream(commandOutput, "utf-8");

    Mockito.when(runtimeMock.exec(command)).thenReturn(processMock);
    Mockito.when(processMock.waitFor()).thenReturn(1);
    Mockito.when(processMock.getInputStream()).thenReturn(input);

    String response = shellCommandUtils.executeCommand(command);
    Assert.assertEquals(commandOutput, response);
    Mockito.verify(processMock).waitFor();
}

From source file:com.google.jenkins.plugins.credentials.oauth.KeyUtils.java

/**
 * Writes the given key to the given keyfile, passing it through
 * {@link Secret} to encode the string. Note that, per the documentation of
 * {@link Secret}, this does not protect against an attacker who has full
 * access to the local file system, but reduces the chance of accidental
 * exposure.//  www.  j a  v a2 s .com
 */
public static void writeKeyToFileEncoded(String key, File file) throws IOException {
    if (key == null || file == null) {
        return;
    }
    Secret encoded = Secret.fromString(key);
    writeKeyToFile(IOUtils.toInputStream(encoded.getEncryptedValue(), StandardCharsets.UTF_8), file);
}