List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:ddf.content.provider.filesystem.FileSystemProviderTest.java
@Test public void testUpdate() throws Exception { CreateResponse createResponse = storeContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME); String id = createResponse.getCreatedContentItem().getId(); ContentItem updateItem = new IncomingContentItem(id, IOUtils.toInputStream("Updated NITF"), NITF_MIME_TYPE); UpdateRequest updateRequest = new UpdateRequestImpl(updateItem); UpdateResponse updateResponse = provider.update(updateRequest); ContentItem item = updateResponse.getUpdatedContentItem(); System.out.println("Item retrieved: " + item); assertEquals(id, item.getId());// w w w . ja va 2 s.c o m assertEquals(NITF_MIME_TYPE, item.getMimeTypeRawData()); String expectedFilePath = BASE_DIR + File.separator + id + File.separator + item.getFilename(); assertThat(item.getFile().getAbsolutePath(), endsWith(expectedFilePath)); assertTrue(item.getSize() > 0); assertTrue(item.getFile().exists()); String updatedFileContents = getFileContentsAsString(item.getFile().getAbsolutePath()); assertEquals("Updated NITF", updatedFileContents); }
From source file:com.temenos.useragent.generic.mediatype.JsonEntityHandler.java
@Override public InputStream getContent() { return IOUtils.toInputStream(jsonObject.toString(4)); }
From source file:com.temenos.useragent.generic.mediatype.AtomEntryHandler.java
@Override public InputStream getContent() { validateHandler(); AtomUtil.updateEntryContent(xmlContentHandler.getDocument(), entry); return IOUtils.toInputStream(getContent(entry)); }
From source file:info.joseluismartin.gtc.WmsCache.java
/** * {@inheritDoc}//w w w . j ava 2 s . co m * @throws IOException */ @Override public InputStream parseResponse(InputStream serverStream, String remoteUri, String localUri) throws IOException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(remoteUri); UriComponents remoteComponents = builder.build(); String localUrl = localUri + "/" + getPath(); InputStream is = serverStream; MultiValueMap<String, String> params = remoteComponents.getQueryParams(); if (GET_CAPABILITIES.equals(params.getFirst(REQUEST))) { String response = IOUtils.toString(serverStream); Document doc = XMLUtils.newDocument(response); if (log.isDebugEnabled()) XMLUtils.prettyDocumentToString(doc); // Fix GetMapUrl Element getMapElement = (Element) doc.getElementsByTagName(GET_MAP).item(0); if (getMapElement != null) { if (log.isDebugEnabled()) { log.debug("Found GetMapUrl: " + this.getMapUrl); } NodeList nl = getMapElement.getElementsByTagName(ONLINE_RESOURCE_ELEMENT); if (nl.getLength() > 0) { Element resource = (Element) nl.item(0); if (resource.hasAttributeNS(XLINK_NS, HREF_ATTRIBUTE)) { this.getMapUrl = resource.getAttributeNS(XLINK_NS, HREF_ATTRIBUTE).replace("?", ""); resource.setAttributeNS(XLINK_NS, HREF_ATTRIBUTE, localUrl); } } } // Fix GetFeatureInfoUrl Element getFeatureElement = (Element) doc.getElementsByTagName(GET_FEATURE_INFO).item(0); if (getFeatureElement != null) { if (log.isDebugEnabled()) { log.debug("Found GetFeatureInfoUrl: " + this.getFeatureInfoUrl); } NodeList nl = getFeatureElement.getElementsByTagName(ONLINE_RESOURCE_ELEMENT); if (nl.getLength() > 0) { Element resource = (Element) nl.item(0); if (resource.hasAttributeNS(XLINK_NS, HREF_ATTRIBUTE)) { this.getFeatureInfoUrl = resource.getAttributeNS(XLINK_NS, HREF_ATTRIBUTE).replace("?", ""); resource.setAttributeNS(XLINK_NS, HREF_ATTRIBUTE, localUrl); } } } response = XMLUtils.documentToString(doc); response = response.replaceAll(getServerUrl(), localUrl); // response = "<?xml version='1.0' encoding='UTF-8'>" + response; is = IOUtils.toInputStream(response); } return is; }
From source file:com.msopentech.odatajclient.testservice.utils.Commons.java
public static InputStream getLinksAsJSON(final String entitySetName, final Map.Entry<String, Collection<String>> link) throws IOException { final ObjectNode links = new ObjectNode(JsonNodeFactory.instance); links.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + entitySetName + "/$links/" + link.getKey()); final ArrayNode uris = new ArrayNode(JsonNodeFactory.instance); for (String uri : link.getValue()) { final String absoluteURI; if (URI.create(uri).isAbsolute()) { absoluteURI = uri;//from ww w .ja v a2s .c o m } else { absoluteURI = DEFAULT_SERVICE_URL + uri; } uris.add(new ObjectNode(JsonNodeFactory.instance).put("url", absoluteURI)); } if (uris.size() == 1) { links.setAll((ObjectNode) uris.get(0)); } else { links.set("value", uris); } return IOUtils.toInputStream(links.toString()); }
From source file:ee.ria.xroad.opmonitordaemon.QueryRequestHandlerTest.java
/** * Ensure that an operational data response contains the required attachment * that is correctly referenced from within the SOAP body. *//*from w ww .j ava2s . com*/ @Test public void handleOperationalDataRequest() throws Exception { InputStream is = new FileInputStream(OPERATIONAL_DATA_REQUEST); SoapParser parser = new SoapParserImpl(); SoapMessageImpl request = (SoapMessageImpl) parser.parse(MimeTypes.TEXT_XML_UTF8, is); QueryRequestHandler handler = new OperationalDataRequestHandler() { @Override protected OperationalDataRecords getOperationalDataRecords(ClientId filterByClient, long recordsFrom, long recordsTo, ClientId filterByServiceProvider, Set<String> outputFields) { return new OperationalDataRecords(Collections.emptyList()); } @Override protected ClientId getClientForFilter(ClientId clientId, SecurityServerId serverId) throws Exception { return null; } }; OutputStream out = new ByteArrayOutputStream(); handler.handle(request, out, ct -> testContentType = ct); String baseContentType = MimeUtils.getBaseContentType(testContentType); assertEquals(MimeTypes.MULTIPART_RELATED, baseContentType); SoapMessageDecoder decoder = new SoapMessageDecoder(testContentType, new SoapMessageDecoder.Callback() { @Override public void soap(SoapMessage message, Map<String, String> headers) throws Exception { assertEquals("cid:" + OperationalDataRequestHandler.CID, findRecordsContentId(message)); } @Override public void attachment(String contentType, InputStream content, Map<String, String> additionalHeaders) throws Exception { String expectedCid = "<" + OperationalDataRequestHandler.CID + ">"; assertEquals(expectedCid, additionalHeaders.get("content-id")); } @Override public void onCompleted() { // Do nothing. } @Override public void onError(Exception t) throws Exception { throw t; } @Override public void fault(SoapFault fault) throws Exception { throw fault.toCodedException(); } }); decoder.parse(IOUtils.toInputStream(out.toString())); }
From source file:ca.nines.ise.util.XMLDriver.java
/** * Parse a string for XML. Mostly useful for testing. * * @param in/*from w w w. j ava 2 s. c o m*/ * @return Document * @throws TransformerException */ public Document drive(String in) throws TransformerException { Document doc = docBuilder.newDocument(); DOMResult domResult = new DOMResult(doc); LocationAnnotator locationAnnotator = new LocationAnnotator(xmlReader, doc); InputSource inputSource = new InputSource(IOUtils.toInputStream(in)); SAXSource saxSource = new SAXSource(locationAnnotator, inputSource); nullTransformer.transform(saxSource, domResult); return doc; }
From source file:com.vmware.o11n.plugin.powershell.model.RemotePsType.java
private void initDomDocument() { if (doc == null && xml != null) { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); // domFactory.setNamespaceAware(true); // never forget this! DocumentBuilder builder;// w w w.j av a 2 s . co m try { builder = domFactory.newDocumentBuilder(); doc = builder.parse(IOUtils.toInputStream(xml)); } catch (ParserConfigurationException e) { throw new PowerShellException(e.getMessage(), e); } catch (SAXException e) { throw new PowerShellException(e.getMessage(), e); } catch (IOException e) { throw new PowerShellException(e.getMessage(), e); } xpathFactory = XPathFactory.newInstance(); } }
From source file:dz.alkhwarizmix.framework.java.utils.impl.XMLUtil.java
protected IAlKhwarizmixDomainObjectList internal_unmarshalObjectListFromXML( // NOPMD final String xmlValue) { return (IAlKhwarizmixDomainObjectList) jaxb2Marshaller .unmarshal(new StreamSource(IOUtils.toInputStream(xmlValue))); }
From source file:com.lightbox.android.webservices.requests.ApiRequest.java
private InputStream printJsonInDebugMode(InputStream inputStream) { Context context = AndroidUtils.getApplicationContext(); if (context != null && AndroidUtils.isDebuggable(context)) { String jsonStr;//from w w w. j ava 2 s. co m try { jsonStr = IOUtils.toString(inputStream); inputStream = IOUtils.toInputStream(jsonStr); DebugLog.d(TAG, jsonStr); } catch (IOException e) { /* Ignore */ } } return inputStream; }