List of usage examples for org.apache.commons.io IOUtils copy
public static void copy(Reader input, OutputStream output) throws IOException
Reader
to bytes on an OutputStream
using the default character encoding of the platform, and calling flush. From source file:de.bmarwell.j9kwsolver.util.HttpConnectorFactory.java
/** * Returns the Body from the URI via http request. * @param uri the URI to get the body from. * @return the Body as String.//from w w w .java 2 s . co m */ public static String getBodyFromRequest(final URI uri) { CloseableHttpResponse response = null; String responseBody = null; HttpGet httpGet = new HttpGet(uri); LOG.debug("Requesting URI: {}.", httpGet.getURI()); try { response = httpClient.execute(httpGet); StringWriter writer = new StringWriter(); IOUtils.copy(response.getEntity().getContent(), writer); responseBody = writer.toString(); } catch (IOException e) { LOG.error("Fehler beim HTTP Request!", e); } return responseBody; }
From source file:com.intropro.prairie.format.seq.SequenceFormatWriter.java
@Override public void close() throws IOException { writer.close();/*ww w . j av a2s .c om*/ InputStream inputStream = new FileInputStream(tmpFile); IOUtils.copy(inputStream, outputStream); inputStream.close(); outputStream.close(); tmpFile.delete(); }
From source file:com.silverpeas.directory.servlets.ImageDisplay.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { ImageProfil profile = new ImageProfil(getAvatar(req)); InputStream in = null;/*w ww . ja v a 2s .com*/ OutputStream out = null; try { in = profile.getImage(); out = res.getOutputStream(); IOUtils.copy(in, out); } finally { if (in != null) { IOUtils.closeQuietly(in); } if (out != null) { IOUtils.closeQuietly(out); } } }
From source file:de.jakusys.jackhammer.cli.command.DownloadFile.java
@Override public void run() { try {// w w w .j a v a 2 s.c o m Session session = getSession(); Node rootNode = session.getRootNode(); NodeIterator nodeIterator = rootNode.getNodes(); while (nodeIterator.hasNext()) { Node next = nodeIterator.nextNode(); System.out.println("next = " + next.getPath()); } Node node = rootNode.getNode(path); InputStream inputStream = JcrUtils.readFile(node); String filename = node.getName(); File file = new File(filename); file.createNewFile(); OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); outputStream.close(); } catch (RepositoryException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.micromata.genome.gwiki.page.gspt.BodyContentImpl.java
@Override public void writeOut(Writer out) throws IOException { IOUtils.copy(getReader(), out); }
From source file:com.gooddata.gdc.DatastoreServiceAT.java
@Test(groups = "datastore", dependsOnMethods = "datastoreUpload") public void datastoreDownload() throws Exception { DataStoreService dataStoreService = gd.getDataStoreService(); final File file = File.createTempFile("file", ".txt"); try (InputStream stream = dataStoreService.download(this.file)) { file.deleteOnExit();/* w ww .ja v a2 s . c om*/ IOUtils.copy(stream, new FileOutputStream(file)); } finally { file.delete(); } }
From source file:edu.tum.cs.mylyn.provisioning.git.xml.RepositoryWrapperTest.java
@Before public void setUp() throws IOException, ConfigInvalidException { MockitoAnnotations.initMocks(this); DfsRepositoryDescription dfsRepositoryDescription = new DfsRepositoryDescription("test"); repository = new UniqueInMemoryRepository(dfsRepositoryDescription); InputStream stream = new FileInputStream(new File("fixtures/repository-config")); StringWriter writer = new StringWriter(); IOUtils.copy(stream, writer); repository.getConfig().fromText(writer.toString()); repository.create();//from ww w. j a v a 2 s . c o m }
From source file:com.t3.net.FTPLocation.java
@Override public void putContent(InputStream content) throws IOException { try (OutputStream os = new URL(composeFileLocation()).openConnection().getOutputStream()) { IOUtils.copy(content, os); IOUtils.closeQuietly(content);/*from www .j a va2 s .co m*/ } }
From source file:com.rest4j.BinaryResource.java
@Override public void write(OutputStream os) throws IOException { IOUtils.copy(is, os); is.close(); }
From source file:com.zaubersoftware.mule.module.jenkins.template.velocity.VelocityTemplate.java
/** * Creates the VelocityTemplate.//from ww w . j a v a 2 s. c o m * */ public VelocityTemplate(final Resource content, final String charset) { Validate.notNull(content); Validate.notNull(charset); InputStream is = null; try { is = content.getInputStream(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); IOUtils.copy(is, os); os.close(); message = os.toString(charset); } catch (final IOException e) { throw new UnhandledException(e); } finally { IOUtils.closeQuietly(is); } }