List of usage examples for org.apache.commons.io.input ReaderInputStream ReaderInputStream
public ReaderInputStream(Reader reader)
From source file:org.lobid.lodmill.TarReader.java
@Override public void process(final Reader reader) { TarArchiveInputStream tarInputStream = null; try {/* ww w . ja va 2 s . c o m*/ tarInputStream = new TarArchiveInputStream(new ReaderInputStream(reader)); TarArchiveEntry entry = null; while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) { if (!entry.isDirectory()) { byte[] buffer = new byte[(int) entry.getSize()]; while ((tarInputStream.read(buffer)) > 0) { getReceiver().process(new StringReader(new String(buffer))); } } } tarInputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(tarInputStream); } }
From source file:org.lockss.util.TestStreamUtil.java
public void testGetReaderShortcut() throws Exception { StringReader rdr = new StringReader("foo"); ReaderInputStream in = new ReaderInputStream(rdr); Reader r2 = StreamUtil.getReader(in, null); assertSame(rdr, r2);//from w ww.ja va 2s. c o m assertReaderMatchesString("foo", r2); }
From source file:org.meresco.triplestore.TransactionItem.java
public static TransactionItem read(String tsItem) throws Exception { try {/* w ww . j a va 2s .com*/ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); Document doc = domFactory.newDocumentBuilder().parse(new ReaderInputStream(new StringReader(tsItem))); return new TransactionItem(actionXPath.evaluate(doc), identifierXPath.evaluate(doc), new String(Base64.decodeBase64(filedataXPath.evaluate(doc)))); } catch (Exception e) { throw e; } }
From source file:org.mule.test.oauth.internal.DancerConfigTestCase.java
@Before public void before() throws Exception { final HttpService httpService = mock(HttpService.class); final HttpClientFactory httpClientFactory = mock(HttpClientFactory.class); httpClient = mock(HttpClient.class); when(httpClientFactory.create(any())).thenReturn(httpClient); when(httpService.getClientFactory()).thenReturn(httpClientFactory); final HttpServerFactory httpServerFactory = mock(HttpServerFactory.class); httpServer = mock(HttpServer.class); when(httpServer.addRequestHandler(anyString(), requestHandlerCaptor.capture())) .thenReturn(mock(RequestHandlerManager.class)); when(httpServer.addRequestHandler(any(), anyString(), requestHandlerCaptor.capture())) .thenReturn(mock(RequestHandlerManager.class)); when(httpServerFactory.create(any())).thenReturn(httpServer); when(httpService.getServerFactory()).thenReturn(httpServerFactory); service = new DefaultOAuthService(httpService, mock(SchedulerService.class)); final HttpResponse httpResponse = mock(HttpResponse.class); final InputStreamHttpEntity httpEntity = mock(InputStreamHttpEntity.class); when(httpEntity.getContent()).thenReturn(new ReaderInputStream(new StringReader(""))); when(httpResponse.getEntity()).thenReturn(httpEntity); when(httpClient.send(any(), anyInt(), anyBoolean(), any())).thenReturn(httpResponse); }
From source file:org.onosproject.d.config.sync.impl.netconf.NetconfDeviceConfigSynchronizerProviderTest.java
protected CompositeStream toCompositeStream(String id, String inXml) { try {/* w ww . j av a 2s .c o m*/ InputStream xml = new ReaderInputStream(CharSource.wrap(inXml).openStream()); return new DefaultCompositeStream(id, xml); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.outermedia.solrfusion.TestHelper.java
public static InputStream embeddedQueryToXmlInputStream(SolrParams request, QueryResponse response) { XMLResponseWriter xmlWriter = new XMLResponseWriter(); Writer w = new StringWriter(); SolrQueryResponse sResponse = new SolrQueryResponse(); sResponse.setAllValues(response.getResponse()); try {/*w w w . j a v a 2 s .c o m*/ xmlWriter.write(w, new LocalSolrQueryRequest(null, request), sResponse); } catch (IOException e) { throw new RuntimeException("Unable to convert Solr response into XML", e); } StringReader stringReader = new StringReader(w.toString()); ReaderInputStream readerInputStream = new ReaderInputStream(stringReader); return readerInputStream; }
From source file:org.ow2.petals.camel.component.mocks.PetalsCamelContextMock.java
public Exchange createExchange(final String serviceId, final String body) throws MessagingException { final Exchange exchange = createExchange(serviceId); exchange.setInMessageContent(new ReaderInputStream(new StringReader(body))); return exchange; }
From source file:org.ow2.petals.camel.component.PetalsCamelProducerTest.java
private void transform(final Exchange exchange) { if (applied) { return;//w ww. ja v a2 s .c om } final Object c = content(); try { if (c instanceof String) { final Source msg = new StreamSource(new ReaderInputStream(new StringReader((String) c))); if (isFault()) { final Fault fault = exchange.createFault(); fault.setContent(msg); exchange.setFault(fault); } else { exchange.setOutMessageContent(msg); } } else if (c instanceof Exception) { exchange.setError((Exception) c); } else if (c == null) { exchange.setDoneStatus(); } else { throw new UncheckedException("Shouldn't happen"); } applied = true; } catch (final MessagingException e) { throw new UncheckedException(e); } }
From source file:org.pentaho.platform.util.client.ClientUtilsTest.java
@Test public void getHttpClientTest() { HttpClient clientSpy = spy(ClientUtil.getClient("admin", "password")); GetMethod method = mock(GetMethod.class); try {//from w w w.jav a2 s .c om doReturn(200).when(clientSpy).executeMethod(method); InputStream inputStream = new ReaderInputStream(new StringReader(XML_TEXT)); when(method.getResponseBodyAsStream()).thenReturn(inputStream); Document document = ClientUtil.getResultDom4jDocument(clientSpy, method); assertTrue(document.getRootElement().getName().equals("Level1")); } catch (IOException | ServiceException e) { assertTrue("Shouldn't have thrown exception here", false); } }
From source file:org.pentaho.platform.util.client.ClientUtilsTest.java
@Test(expected = ServiceException.class) public void testgetResultDom4jDocumentException3() throws Exception { HttpClient client = spy(ClientUtil.getClient("username", "password")); GetMethod method = mock(GetMethod.class); doReturn(200).when(client).executeMethod(method); InputStream inputStream = new ReaderInputStream(new StringReader(XML_BROKEN)); when(method.getResponseBodyAsStream()).thenReturn(inputStream); Document document = null;//from www . j a v a 2 s. c o m document = ClientUtil.getResultDom4jDocument(client, method); assertNull(document); }