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:jazsync.UploadTests.java

@Test
public void testParseParams() throws IOException {

    String uploadString = version + blocksize + filelength + someKV + sha1 + relocString + rangeString;

    Upload um = Upload.parse(IOUtils.toInputStream(uploadString));

    Assert.assertEquals(1024, um.getBlocksize());
    Assert.assertEquals("testVersion", um.getVersion());
    Assert.assertEquals(32768, um.getFilelength());
    Assert.assertEquals("sha1checksum", um.getSha1());

}

From source file:edu.xjtu.qxcamerabridge.DescriptorXMLParser.java

/**
 * parse the xml device descriptor. extract the API service URL
 * @return the extracted URLs are stored in the map. The key is the api service name and the value is the dedicated url.
 * @throws ParserConfigurationException/*from   w ww.  j  ava 2  s. c om*/
 * @throws SAXException
 * @throws IOException 
 */
public Map<String, String> parseXML() throws ParserConfigurationException, SAXException, IOException {
    Map<String, String> serviceMap = new HashMap();
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(IOUtils.toInputStream(pageContent));
    Element root = document.getDocumentElement();
    Element device = (Element) root.getElementsByTagName("device").item(0);
    Element deviceName = (Element) device.getElementsByTagName("friendlyName").item(0);
    serviceMap.put("deviceName", deviceName.getTextContent());
    Element device_info = (Element) device.getElementsByTagName("av:X_ScalarWebAPI_DeviceInfo").item(0);
    Element serviceList = (Element) device_info.getElementsByTagName("av:X_ScalarWebAPI_ServiceList").item(0);
    // extract the servicelist

    for (int i = 0; i < serviceList.getChildNodes().getLength(); i++) {
        Element eachservice = (Element) serviceList.getElementsByTagName("av:X_ScalarWebAPI_Service").item(i);
        Element servicetype = (Element) eachservice.getElementsByTagName("av:X_ScalarWebAPI_ServiceType")
                .item(0);
        Element actionURL = (Element) eachservice.getElementsByTagName("av:X_ScalarWebAPI_ActionList_URL")
                .item(0);
        serviceMap.put(servicetype.getTextContent(), actionURL.getTextContent());

    }
    Element imagingDevice = (Element) device_info.getElementsByTagName("av:X_ScalarWebAPI_ImagingDevice")
            .item(0);
    Element liveviewURL = (Element) imagingDevice.getElementsByTagName("av:X_ScalarWebAPI_LiveView_URL")
            .item(0);
    serviceMap.put("liveViewURL", liveviewURL.getTextContent());

    return serviceMap;
}

From source file:com.sap.research.connectivity.gw.GwUtils.java

public static void createFileFromString(String subFolder, String targetFileName, String content,
        FileManager fileManager) {//ww w  .j  a va  2  s  .  c  o  m
    InputStream inputStream = null;
    OutputStream outputStream = null;
    String targetFile = subFolder + SEPARATOR + targetFileName;
    MutableFile mutableFile = fileManager.exists(targetFile) ? fileManager.updateFile(targetFile)
            : fileManager.createFile(targetFile);
    try {
        inputStream = IOUtils.toInputStream(content);
        outputStream = mutableFile.getOutputStream();
        //System.out.println(inputStreamString);
        IOUtils.copy(inputStream, outputStream);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
        IOUtils.closeQuietly(outputStream);
    }
}

From source file:it.govpay.core.utils.client.SOAPUtils.java

public static Object unmarshal(byte[] msg, Schema schema)
        throws JAXBException, SAXException, IOException, XMLStreamException {
    String s = new String(msg);
    InputStream is = IOUtils.toInputStream(s);
    return unmarshal(is, schema);
}

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

@Override
public void setPayload(String payload) {
    if (payload == null) {
        return;//  w  w  w .j  a  v  a 2s. c  o  m
    }
    ReadableRepresentation jsonRepresentation = representationFactory.readRepresentation(
            RepresentationFactory.HAL_JSON, new InputStreamReader(IOUtils.toInputStream(payload)));
    representation = jsonRepresentation;
}

From source file:com.wantez.eregparser.Parser.java

public String parse(final String document) throws TransformerException, UnsupportedEncodingException {
    Source streamSource = new StreamSource(IOUtils.toInputStream(document));
    String result;//from w  w w  .  j  a v a2s .co m
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Result streamResult = new StreamResult(baos);
    this.transformer.transform(streamSource, streamResult);
    result = baos.toString("ISO-8859-1");
    return result;
}

From source file:de.slub.fedora.jms.MessageMapper.java

private static String extractDsId(String text)
        throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(IOUtils.toInputStream(text));

    return (String) xPath.evaluate("/entry/category[@scheme='fedora-types:dsID']/@term", document,
            XPathConstants.STRING);
}

From source file:edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarXmlTestCase.java

public static <R> R parseDocumentString(StudyCalendarXmlSerializer<R> serializer, String doc) {
    return serializer.readDocument(IOUtils.toInputStream(doc));
}

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

@Override
public List<EntityWrapper> entities() {
    List<EntityWrapper> entityWrappers = new ArrayList<EntityWrapper>();
    for (ReadableRepresentation itemRepresentation : representation.getResourcesByRel("item")) {
        EntityWrapper entityWrapper = new DefaultEntityWrapper();
        HalJsonEntityHandler entityHandler = new HalJsonEntityHandler();
        entityHandler//  w  w w  . j a va2s  . c  o  m
                .setContent(IOUtils.toInputStream(itemRepresentation.toString(RepresentationFactory.HAL_JSON)));
        entityWrapper.setHandler(entityHandler);
        entityWrappers.add(entityWrapper);
    }
    return entityWrappers;
}

From source file:com.medvision360.medrecord.basex.XmlWrappedArchetypeConverter.java

@Override
public WrappedArchetype parse(InputStream is, String encoding) throws IOException, ParseException {
    Document d = toDocument(is, encoding);

    String asString = xpath(d, "//asString", Filters.element());
    //        System.out.println("--------------------------");
    //        String[] lines = asString.split("\r?\n");
    //        for (int i = 0; i < lines.length; i++)
    //        {/*from  ww  w.j a va2 s .co  m*/
    //            String line = lines[i];
    //            int lineNo = i + 1;
    //            System.out.println(""+lineNo+": "+line);
    //        }
    //        System.out.println("--------------------------");
    boolean locked = Boolean.parseBoolean(xpath(d, "//locked", Filters.element()));

    InputStream asInputStream = IOUtils.toInputStream(asString);
    WrappedArchetype result = m_delegate.parse(asInputStream, encoding);
    return new WrappedArchetype(asString, result.getArchetype(), locked);
}