@Test public void testToBufferedInputStream_InputStream() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final InputStream in = IOUtils.toBufferedInputStream(fin); final byte[] out = IOUtils.toByteArray(in); assertNotNull(out); assertEquals("Not all bytes were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
@Test public void testToBufferedInputStreamWithBufferSize_InputStream() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final InputStream in = IOUtils.toBufferedInputStream(fin, 2048); final byte[] out = IOUtils.toByteArray(in); assertNotNull(out); assertEquals("Not all bytes were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
/** * Fetches entire contents of an <code>InputStream</code> and represent * same data as result InputStream. * <p> * This method is useful where, * <ul> * <li>Source InputStream is slow.</li> * <li>It has network resources associated, so we cannot keep it open for * long time.</li> * <li>It has network timeout associated.</li> * </ul> * It can be used in favor of {@link #toByteArray(InputStream)}, since it * avoids unnecessary allocation and copy of byte[].<br> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input Stream to be fully buffered. * @return A fully buffered stream. * @throws IOException if an I/O error occurs */ public static InputStream toBufferedInputStream(InputStream input) throws IOException { return org.apache.commons.io.IOUtils.toBufferedInputStream(input); }
protected void loadConfig(File configFile) throws IOException { FileInputStream configStream = new FileInputStream(configFile); InputStream bufferedConfigStream = IOUtils.toBufferedInputStream(configStream); loadConfigFromStream(bufferedConfigStream); }
@Override public InputStream handleResponse(HttpResponse response) throws IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { InputStream content = entity.getContent(); return IOUtils.toBufferedInputStream(content); } HttpUtil.consumeEntity(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); }
private void run() throws Exception { // deserialize DefaultWordformStore<?> ws = (DefaultWordformStore<?>) deserialize(toBufferedInputStream( openInputStream(serFile))); // print PrintWriter out; boolean closeOut; if (outFile == null) { out = new PrintWriter(System.out, true); closeOut = false; } else { OutputStream os = openOutputStream(outFile); out = new PrintWriter(new BufferedWriter( new OutputStreamWriter(os, "utf-8")), true); closeOut = true; } try { for (Map.Entry<String, ?> e : ws.strKeyMap.entrySet()) { out.print(escapeTabs(e.getKey())); out.print('\t'); out.print(e.getValue()); out.println(); } } finally { if (closeOut) closeQuietly(out); } }
return new InputStreamReader(IOUtils.toBufferedInputStream(partialTemplateStream)); } catch (IOException e) { throw new RuntimeException(e);
return new InputStreamReader(IOUtils.toBufferedInputStream(partialTemplateStream)); } catch (IOException e) { throw new RuntimeException(e);
public static void readTaxonomy(OpenTreeListener listener, InputStream inputStream) throws IOException { LabeledCSVParser parser = CSVTSVUtil.createLabeledCSVParser(new CSVParser(IOUtils.toBufferedInputStream(inputStream), '\t')); while (parser.getLine() != null) { String taxonId = parser.getValueByLabel("uid"); String[] externalIds = StringUtils.split(parser.getValueByLabel("sourceinfo"), ","); for (String otherTaxonId : externalIds) { listener.taxonSameAs(taxonId, otherTaxonId); } } }
CloseableHttpResponse response = execEnhance(request); try { result = IOUtils.toBufferedInputStream(response.getEntity().getContent()); } finally { response.close();