List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:com.github.restdriver.clientdriver.unit.ClientDriverResponseTest.java
@Test public void creatingResponseWithEmptyInputStreamGives200Status() { ClientDriverResponse response = new ClientDriverResponse(IOUtils.toInputStream(""), "application/octet-stream"); assertThat(response.getStatus(), is(200)); }
From source file:com.adobe.acs.commons.components.longformtext.impl.LongFormTextComponentImpl.java
@Override public final String[] getTextParagraphs(final String text) { List<String> paragraphs = new ArrayList<String>(); try {//from w ww. j av a 2s . co m final Document doc = htmlParser.parse(null, IOUtils.toInputStream(text), "UTF-8"); doc.getDocumentElement().normalize(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); final NodeList bodies = doc.getElementsByTagName("body"); if (bodies != null && bodies.getLength() == 1) { final org.w3c.dom.Node body = bodies.item(0); final NodeList children = body.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); final org.w3c.dom.Node child = children.item(i); if (child == null) { log.warn("Found a null dom node."); continue; } else if (child.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) { log.warn("Found a dom node is not an element; skipping"); continue; } stripNamespaces(child); transformer.transform(new DOMSource(child), result); writer.flush(); final String outerHTML = writer.toString(); if (StringUtils.isNotBlank(outerHTML)) { paragraphs.add(outerHTML); } } } else { log.debug("HTML does not have a single body tag. Cannot parse as expected."); } } catch (Exception e) { log.warn("Long Form Text encountered a parser error: {}", e); } return paragraphs.toArray(new String[paragraphs.size()]); }
From source file:gov.nasa.ensemble.resources.TestProjectProperties.java
@Before public void before() throws CoreException { proj.create(null); proj.open(null); file.create(IOUtils.toInputStream(""), true, null); }
From source file:com.msopentech.odatajclient.proxy.MediaEntityTestITCase.java
@Test public void update() throws IOException { final Car car = container.getCar().get(14); assertNotNull(car);/*from w w w. j av a 2 s .c om*/ final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")"; InputStream input = IOUtils.toInputStream(TO_BE_UPDATED); car.setStream(input); container.flush(); input = container.getCar().get(14).getStream(); assertEquals(TO_BE_UPDATED, IOUtils.toString(input)); IOUtils.closeQuietly(input); }
From source file:de.qucosa.fedora.FedoraRepositoryTest.java
@Test public void modifiesDatastreamContent() throws Exception { ModifyDatastreamResponse mockResponse = mock(ModifyDatastreamResponse.class); when(mockResponse.getStatus()).thenReturn(200); when(fedoraClient.execute(any(ModifyDatastream.class))).thenReturn(mockResponse); InputStream testInputStream = IOUtils.toInputStream("testInputData"); fedoraRepository.modifyDatastreamContent("test:1", "TEST-DS", "text", testInputStream); verify(fedoraClient).execute(any(ModifyDatastream.class)); }
From source file:com.lightboxtechnologies.nsrl.RecordLoaderTest.java
@Test public void loadInputStream() throws IOException { final LineHandler lh = buildLineHandler(limit, line); final RecordLoader loader = new RecordLoader(); InputStream in = null;/* w w w.ja v a2 s. c o m*/ try { in = IOUtils.toInputStream(buildInput(limit, line).toString()); loader.load(in, lh); in.close(); } finally { IOUtils.closeQuietly(in); } }
From source file:com.github.restdriver.clientdriver.jetty.DefaultClientDriverJettyHandlerTest.java
@Before public void before() throws IOException { mockRequestMatcher = mock(RequestMatcher.class); mockRequest = mock(Request.class); mockHttpRequest = mock(Request.class); mockHttpResponse = mock(HttpServletResponse.class); mockServletOutputStream = mock(ServletOutputStream.class); ServletInputStream servletInputStream = new DummyServletInputStream(IOUtils.toInputStream("")); realRequest = new ClientDriverRequest("/").withMethod(Method.GET); realResponse = new ClientDriverResponse("entity payload", "text/plain").withStatus(200).withHeader("Test", "header-should-be-set-before-writing-body"); when(mockHttpRequest.getInputStream()).thenReturn(servletInputStream); when(mockHttpRequest.getMethod()).thenReturn("GET"); when(mockHttpRequest.getReader()).thenReturn(new BufferedReader(new StringReader(""))); when(mockRequestMatcher.isMatch((RealRequest) anyObject(), (ClientDriverRequest) anyObject())) .thenReturn(true);// w w w.j av a 2 s . com when(mockHttpResponse.getOutputStream()).thenReturn(mockServletOutputStream); }
From source file:net.sasasin.sreader.batch.ContentHeaderDriver.java
@SuppressWarnings("unchecked") private void fetchByRome(FeedUrl f, Set<ContentHeader> c) { try {/*from ww w. j a va2s . c om*/ // ?RSS InputStream is = IOUtils.toInputStream(new WgetHttpComponentsImpl(new URL(f.getUrl())).read()); // Rome SyndFeed feed = new SyndFeedInput().build(new XmlReader(is)); for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) { logger.info(this.getClass().getSimpleName() + " processing " + entry.getLink()); ContentHeader ch = new ContentHeader(); // HTTP 30xmoved?URL?? // 30x???????new URL(entry.getLink())???? URL entryUrl = new WgetHttpComponentsImpl(new URL(entry.getLink())).getOriginalUrl(); ch.setUrl(entryUrl.toString()); ch.setId(Md5Util.crypt(ch.getUrl())); ch.setTitle(entry.getTitle()); ch.setFeedUrl(f); c.add(ch); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (FeedException e) { e.printStackTrace(); } }
From source file:com.collective.celos.ci.testing.fixtures.convert.JsonExpandConverter.java
@Override public FixFile convert(TestRun tr, FixFile ff) throws Exception { List<String> stringList = Lists.newArrayList(); BufferedReader reader = new BufferedReader(new InputStreamReader(ff.getContent())); String line;//from ww w .java 2 s. c o m while ((line = reader.readLine()) != null) { JsonElement jsonElement = jsonParser.parse(line); for (String field : expandFields) { try { String strField = jsonElement.getAsJsonObject().get(field).getAsString(); JsonElement fieldElem = jsonParser.parse(strField); jsonElement.getAsJsonObject().add(field, fieldElem); } catch (Exception e) { throw new Exception("Error caused in line: " + line + " trying to expand field: " + field, e); } } stringList.add(gson.toJson(jsonElement)); } return new FixFile(IOUtils.toInputStream(StringUtils.join(stringList, "\n"))); }
From source file:com.thoughtworks.go.server.view.velocity.TestVelocityView.java
public void setupAdditionalFakeTemplate(String templateName, String fakeContent) { setupContentResource(loader, runtimeServices, templateName, fakeContent); additionalTemplates//from w w w .j ava 2 s . com .add(setupTemplate(loader, runtimeServices, templateName, IOUtils.toInputStream(fakeContent))); }