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:com.redhat.red.offliner.PomArtifactListReaderTest.java
@BeforeClass public static void prepare() throws IOException { File tempDir = new File(TEMP_POM_DIR); if (tempDir.exists()) { FileUtils.deleteDirectory(tempDir); }// w ww . jav a2s . c o m tempDir.mkdirs(); List<String> resources = new ArrayList<String>(2); resources.add("repo.pom"); resources.add("settings.xml"); for (String resource : resources) { InputStream is = PomArtifactListReaderTest.class.getClassLoader().getResourceAsStream(resource); File target = new File(TEMP_POM_DIR, resource); OutputStream os = new FileOutputStream(target); try { IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } } }
From source file:com.github.javaparser.wiki_samples.TestFileToken.java
public TestFileToken(String filename) { this.filename = filename; try {/*from w w w .ja va 2s . co m*/ try (InputStream i = getClass().getResourceAsStream("TestFile.java"); OutputStream o = new FileOutputStream(filename)) { assertNotNull(i); IOUtils.copy(i, o); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:com.aurel.track.exchange.docx.exporter.LaTeXExportBL.java
/** * Serializes the docx content into the response's output stream * @param response// ww w. j av a 2 s . c om * @param wordMLPackage * @return */ static String prepareReportResponse(HttpServletResponse response, TWorkItemBean workItem, ReportBeans reportBeans, TPersonBean user, Locale locale, String templateDir, String templateFile) { ReportBeansToLaTeXConverter rl = new ReportBeansToLaTeXConverter(); File pdf = rl.generatePdf(workItem, reportBeans.getItems(), true, locale, user, "", "", false, new File(templateFile), new File(templateDir)); OutputStream outputStream = null; try { outputStream = response.getOutputStream(); InputStream is = new FileInputStream(pdf); IOUtils.copy(is, outputStream); is.close(); } catch (FileNotFoundException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.error("Getting the output stream failed with " + e.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } return null; }
From source file:dotplugin.GraphViz.java
private static File execute(final InputStream input, String format) throws CoreException { MultiStatus status = new MultiStatus(Activator.ID, 0, "Errors occurred while running Graphviz", null); // we keep the input in memory so we can include it in error messages ByteArrayOutputStream dotContents = new ByteArrayOutputStream(); File dotInput = null, dotOutput = null; try {//from w w w .j av a 2 s. com // determine the temp input and output locations dotInput = File.createTempFile(TMP_FILE_PREFIX, DOT_EXTENSION); dotOutput = File.createTempFile(TMP_FILE_PREFIX, "." + format); dotInput.deleteOnExit(); dotOutput.deleteOnExit(); FileOutputStream tmpDotInputStream = null; try { IOUtils.copy(input, dotContents); tmpDotInputStream = new FileOutputStream(dotInput); IOUtils.copy(new ByteArrayInputStream(dotContents.toByteArray()), tmpDotInputStream); } finally { IOUtils.closeQuietly(tmpDotInputStream); } IStatus result = runDot(format, dotInput, dotOutput); status.add(result); // status.add(logInput(dotContents)); if (!result.isOK()) LogUtils.log(status); return dotOutput; } catch (SWTException e) { status.add(new Status(IStatus.ERROR, Activator.ID, "", e)); } catch (IOException e) { status.add(new Status(IStatus.ERROR, Activator.ID, "", e)); } throw new CoreException(status); }
From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getPathInfo().contains("..")) { resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Illegal path"); return;/* www.ja v a2 s . c om*/ } String resource = resourcePath(req.getPathInfo()); String mimeType = contentType(req.getPathInfo()); if (mimeType != null) { resp.setContentType(mimeType); } // TODO: this is primitive. Should add content-length at least InputStream resStream = getClass().getResourceAsStream(resource); if (resStream == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } else { IOUtils.copy(resStream, resp.getOutputStream()); } }
From source file:me.mast3rplan.phantombot.HTTPResponse.java
HTTPResponse(String address, String request) throws IOException { Socket sock = new Socket(address, 80); Writer output = new StringWriter(); IOUtils.write(request, sock.getOutputStream(), "utf-8"); IOUtils.copy(sock.getInputStream(), output); com.gmt2001.Console.out.println(output.toString()); Scanner scan = new Scanner(sock.getInputStream()); String errorLine = scan.nextLine(); for (String line = scan.nextLine(); !line.equals(""); line = scan.nextLine()) { String[] keyval = line.split(":", 2); if (keyval.length == 2) { values.put(keyval[0], keyval[1].trim()); } else {/* ww w. ja va2 s . c o m*/ //? } } while (scan.hasNextLine()) { body += scan.nextLine(); } sock.close(); }
From source file:eu.itesla_project.cim1.converter.CIM1ImporterTest.java
private void copyFile(DataSource dataSource, String filename) throws IOException { try (OutputStream stream = dataSource.newOutputStream(filename, false)) { IOUtils.copy(getClass().getResourceAsStream("/" + filename), stream); }// w w w. ja v a 2s .co m }
From source file:com.compomics.pladipus.core.control.util.ZipUtils.java
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return;//from w w w .j a v a 2 s . co m } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } LOGGER.debug("Extracting: " + entry); try (BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) { IOUtils.copy(inputStream, outputStream); outputStream.flush(); } }
From source file:com.handcraftedbits.bamboo.plugin.go.task.test.FileOutputHandler.java
@Override public void process(@NotNull final InputStream output) throws ProcessException { final FileOutputStream fileOutput; try {//from ww w.j a v a2s .c o m fileOutput = new FileOutputStream(this.file, true); } catch (final FileNotFoundException e) { throw new ProcessException(e); } try { IOUtils.copy(output, fileOutput); } catch (final IOException e) { throw new ProcessException(e); } finally { IOUtils.closeQuietly(fileOutput); } }
From source file:de.mklinger.commons.exec.PipeRunnable.java
@Override protected void doRun() throws IOException { running.set(true);/* www. j a va 2s .c o m*/ started.set(true); try { final int copied = IOUtils.copy(in, out); LOG.debug("Copied {} bytes", copied); } finally { running.set(false); } }