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:net.firejack.platform.api.filestore.FileStoreServiceTest.java

@Test
public void testFileStore() throws IOException {
    ServiceResponse response = OPFEngine.FileStoreService.createDirectory(OpenFlame.FILESTORE_BASE, "test");
    logger.info(response.getMessage());/*from w  ww .  ja  v  a  2  s.  com*/

    InputStream stream = IOUtils.toInputStream("qwe");
    response = OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, "test.txt", stream, "test");
    logger.info(response.getMessage());
    IOUtils.closeQuietly(stream);

    stream = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE, "test.txt", "test");
    String s = IOUtils.toString(stream);
    IOUtils.closeQuietly(stream);
    logger.info(response.getMessage());
    Assert.assertEquals(s, "qwe");

    response = OPFEngine.FileStoreService.deleteFile(OpenFlame.FILESTORE_BASE, "test.txt", "test");
    logger.info(response.getMessage());
    response = OPFEngine.FileStoreService.deleteDirectory(OpenFlame.FILESTORE_BASE, "test");
    logger.info(response.getMessage());

    response = OPFEngine.FileStoreService.readFileStoreInfo();
    logger.info(response.getMessage());
}

From source file:it.polimi.tower4clouds.manager.api.ManagerAPI.java

@Override
public MonitoringRules getRules() throws UnexpectedAnswerFromServerException, IOException {
    String xmlRules = client.execute(RestMethod.GET, managerUrl + MONITORING_RULES_PATH, null, 200, timeout);
    try {//from w ww  . j  a v a2s  .  c  om
        MonitoringRules rules = XMLHelper.deserialize(IOUtils.toInputStream(xmlRules), MonitoringRules.class);
        return rules;
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}

From source file:info.magnolia.jcr.util.PropertiesImportExport.java

/**
 * Each property is one item in the properties varargs passed in.
 *//* w w  w  .j a  va  2 s.c  o  m*/
public void createNodes(Node root, String... properties) throws IOException, RepositoryException {
    createNodes(root, IOUtils.toInputStream(StringUtils.join(Arrays.asList(properties), "\n")));
}

From source file:com.temenos.useragent.generic.mediatype.HalJsonPayloadHandler.java

@Override
public EntityWrapper entity() {
    if (!isCollection()) {
        EntityWrapper wrapper = new DefaultEntityWrapper();
        HalJsonEntityHandler entityHandler = new HalJsonEntityHandler();
        entityHandler//from w ww .j a  v  a 2 s  .c  o m
                .setContent(IOUtils.toInputStream(representation.toString(RepresentationFactory.HAL_JSON)));
        wrapper.setHandler(entityHandler);
        return wrapper;
    }
    return new NullEntityWrapper();
}

From source file:com.elasticbox.jenkins.k8s.repositories.api.PodRepositoryApiImpl.java

@Override
public Pod pod(String kubeName, String namespace, String yaml) throws RepositoryException {
    Pod pod;//  ww w  .  ja va 2s . c  o m
    try {
        pod = kubeRepository.getClient(kubeName).pods().inNamespace(namespace).load(IOUtils.toInputStream(yaml))
                .get();

        return pod;

    } catch (KubernetesClientException exception) {
        final RepositoryException repoException = new RepositoryException("Error while parsing Yaml",
                exception);
        LOGGER.warning("Yaml definition not valid: " + repoException.getCausedByMessages());
        throw repoException;
    }
}

From source file:edu.wustl.xipHost.avt2ext.RetrieveAIMTest.java

@Test
public void testRetrieveAIM_1A() {
    Map<Integer, Object> dicomCriteria = new HashMap<Integer, Object>();
    dicomCriteria.put(Tag.SeriesInstanceUID, "1.3.6.1.4.1.9328.50.1.10697");
    List<ImageAnnotation> imageAnnots = adService.retrieveAnnotations(dicomCriteria, null);
    ImageAnnotation annot = (ImageAnnotation) imageAnnots.get(0);
    //Assert image annotation uniqueIdentifier
    String strXML = annot.getAIM();
    InputStreamReader isr = new InputStreamReader(IOUtils.toInputStream(strXML));
    try {// w  w w . j  a  va 2  s  .co m
        JAXBElement<?> obj = (JAXBElement<?>) u.unmarshal(isr);
        gme.cacore_cacore._3_2.edu_northwestern_radiology.ImageAnnotation imageAnnotation = ((gme.cacore_cacore._3_2.edu_northwestern_radiology.ImageAnnotation) obj
                .getValue());
        String annotID = String.valueOf(imageAnnotation.getUniqueIdentifier());
        //System.out.println(annot.getAIM());
        assertEquals("Wrong annotation retrieved. Expected ID: " + "1.2.288.3.2205383238.1512.1207945935.1"
                + " but actual: " + annotID, annotID, "1.2.288.3.2205383238.1512.1207945935.1");
    } catch (JAXBException e) {
        logger.error(e, e);
    }
}

From source file:com.synclio.hawk.TutorialRouteBuilder.java

@Override
public void configure() throws Exception {
    from("ghttp:///weather").process(new RequestProcessor()).marshal().serialization().to("gtask://default")
            .unmarshal().serialization().process(new ResponseProcessor());

    from("gtask://default").unmarshal().serialization().process(new Processor() {
        @Override/*from  w ww  . j  a v  a2 s  . co m*/
        public void process(Exchange exchange) throws Exception {
            ReportData data = exchange.getIn().getBody(ReportData.class);

            URLFetchService urlFetch = URLFetchServiceFactory.getURLFetchService();
            HTTPRequest req = new HTTPRequest(new URL("http://where.yahooapis.com/v1/places.q(" + data.getCity()
                    + ")?appid=0b4twNzV34GzaTHevW1SzEcnzG4Nyuhq6pvnSKZS.28kCqUw31jPRApe6_niElSL_waLc2M-"),
                    HTTPMethod.GET);
            HTTPResponse resp = urlFetch.fetch(req);

            Document doc = toDocument(IOUtils.toInputStream(new String(resp.getContent())));
            XPathFactory xpfactory = XPathFactory.newInstance();
            XPath xpath = xpfactory.newXPath();
            try {
                System.out.print(xpath.evaluate("//places/place[1]/woeid/text()", doc));
                System.out.print(new String(resp.getContent()));

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });
    //         .setHeader(Exchange.HTTP_METHOD,constant("GET"))
    //         .enrich("ghttp://where.yahooapis.com/v1/places.q(Chennai)?appid=0b4twNzV34GzaTHevW1SzEcnzG4Nyuhq6pvnSKZS.28kCqUw31jPRApe6_niElSL_waLc2M-")         .setHeader(GMailBinding.GMAIL_SUBJECT, constant("Weather report"))
    //         .setHeader(GMailBinding.GMAIL_SENDER, ReportData.requestor())
    //         .setHeader(GMailBinding.GMAIL_TO, ReportData.recipient())
    //         .process(new ReportGenerator())
    //         .to("gmail://default");
}

From source file:com.qualinsight.plugins.sonarqube.badges.ws.SVGImageGenerator.java

/**
 * Generates a SVG image object from a provided Data object.
 *
 * @param data Data object holding data required to produce a SVGGraphics2D object
 * @return generated InputStream to read SVG image from
 *//*from   www  .j a  v a 2 s .  c  o  m*/
public InputStream generateFor(final SVGImageData data) {

    final Map<String, String> replacements = new HashMap<>();
    replacements.put("{{fontFamily}}", data.fontFamily());
    replacements.put("{{labelText}}", data.labelText());
    replacements.put("{{labelBackgroundColor}}", data.labelBackgroundColor().hexColor());
    replacements.put("{{labelWidth}}", data.labelWidth());
    replacements.put("{{labelHalfWidth}}", data.labelHalfWidth());
    replacements.put("{{valueText}}", data.valueText());
    replacements.put("{{valueBackgroundColor}}", data.valueBackgroundColor().hexColor());
    replacements.put("{{valueWidth}}", data.valueWidth());
    replacements.put("{{valueHalfWidth}}", data.valueHalfWidth());
    replacements.put("{{totalWidth}}", data.totalWidth());
    return IOUtils.toInputStream(StringUtils.replaceEach(data.template().content(),
            replacements.keySet().toArray(new String[0]), replacements.values().toArray(new String[0])));
}

From source file:com.temenos.useragent.generic.mediatype.AtomPayloadHandler.java

@Override
public void setPayload(String payload) {
    if (payload == null) {
        throw new IllegalArgumentException("Payload is null");
    }//from   w ww.jav  a2s.  c  o m
    Document<Element> payloadDoc = null;
    try {
        payloadDoc = new Abdera().getParser().parse(IOUtils.toInputStream(payload));
    } catch (Exception e) {
        throw new IllegalArgumentException("Unexpected payload for media type '" + AtomUtil.MEDIA_TYPE + "'.",
                e);
    }
    QName rootElementQName = payloadDoc.getRoot().getQName();
    if (new QName(AtomUtil.NS_ATOM, "feed").equals(rootElementQName)) {
        feed = (Feed) payloadDoc.getRoot();
        isCollection = true;
    } else if (new QName(AtomUtil.NS_ATOM, "entry").equals(rootElementQName)) {
        entityTransformer.setEntry((Entry) payloadDoc.getRoot());
        isCollection = false;
    } else {
        throw new IllegalArgumentException("Unexpected payload for media type '" + AtomUtil.MEDIA_TYPE
                + "'. Payload [" + payloadDoc.getRoot().toString() + "]");
    }
}

From source file:fi.mystes.synapse.mediator.util.XslTransformer.java

/**
 * Created DOMSource object from given XML string content.
 * /*from  w w w  . j ava2  s  .c  om*/
 * @param xml Content to transform to DOMSoure object
 * 
 * @return DOMSource object containing given XML content
 * 
 * @throws ParserConfigurationException If document builder initialization fails
 * @throws SAXException If given XML content parsing fails
 * @throws IOException If given XML content parsing fails
 */
private DOMSource createDomSource(final String xml)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilder builder = createDocumentBuilder();
    Document document = builder.parse(IOUtils.toInputStream(xml));
    return new DOMSource(document);
}