List of usage examples for com.google.common.io Resources copy
public static void copy(URL from, OutputStream to) throws IOException
From source file:org.doctester.rendermachine.RenderMachineImpl.java
private void copyCustomUserSuppliedCssIfItExists() { String baseDirWithCustomCssFileName = BASE_DIR + File.separator + CUSTOM_DOCTESTER_STYLESHEET_FILENAME; try {//ww w. j a v a2s. co m URL url = this.getClass().getClassLoader().getResource(CUSTOM_DOCTESTER_STYLESHEET_LOCATION); if (url == null) { } else { logger.info("Found custom stylesheet at " + CUSTOM_DOCTESTER_STYLESHEET_LOCATION); Resources.copy(url, new FileOutputStream(new File(baseDirWithCustomCssFileName))); } } catch (IOException e) { logger.error("Something went wrong when copying file from " + CUSTOM_DOCTESTER_STYLESHEET_LOCATION + " to real base directory at: " + baseDirWithCustomCssFileName, e); } }
From source file:org.eclipse.scada.configuration.world.lib.deployment.wix.WixDeploymentSetupBuilder.java
private void createLogback(final Element comp, final EquinoxAppService eas, final File resourceBase) throws Exception { final Element file = createElement(comp, "File"); //$NON-NLS-1$ final String serviceName = makeServiceName(eas); file.setAttribute("Id", "logback.xml_" + serviceName); //$NON-NLS-1$ //$NON-NLS-2$ file.setAttribute("Source", String.format("resources\\apps\\%s\\logback.xml", eas.getName())); //$NON-NLS-1$ //$NON-NLS-2$ final File logback = new File(resourceBase, "logback.xml"); //$NON-NLS-1$ try (FileOutputStream out = new FileOutputStream(logback)) { Resources.copy(Resources.getResource(MsiHandler.class, "templates/msi/app.logback.xml"), out); //$NON-NLS-1$ }//from www . ja va2 s .c om }
From source file:com.ning.billing.osgi.bundles.analytics.http.AnalyticsServlet.java
private void doHandleStaticResource(final String resourceName, final HttpServletResponse resp) throws IOException { logService.log(LogService.LOG_INFO, "doHandleStaticResource " + resourceName); final URL resourceUrl = Resources.getResource(resourceName); final String[] parts = resourceName.split("/"); if (parts.length > 2) { if (parts[1].equals("javascript")) { resp.setContentType("application/javascript"); } else if (parts[1].equals("styles")) { resp.setContentType("text/css"); }/* w ww . j a va2s . c om*/ Resources.copy(resourceUrl, resp.getOutputStream()); } else { logService.log(LogService.LOG_INFO, "doHandleStaticResource rewritting html " + resourceName); final ByteArrayOutputStream out = new ByteArrayOutputStream(); Resources.copy(resourceUrl, out); String inputHtml = new String(out.toByteArray()); // TODO STEPH we need to extract real ip port on which http sever is listening to String tmp1 = inputHtml.replace("$VAR_SERVER", "\"127.0.0.1\""); String tmp2 = tmp1.replace("$VAR_PORT", "\"8080\""); resp.getOutputStream().write(tmp2.getBytes()); resp.setContentType("text/html"); } resp.setStatus(HttpServletResponse.SC_OK); }
From source file:org.openqa.selenium.server.SeleniumDriverResourceHandler.java
protected void download(final URL url, final File outputFile) { if (outputFile.exists()) { throw new RuntimeException("Output already exists: " + outputFile); }// ww w . ja v a2s . co m File directory = outputFile.getParentFile(); if (!directory.exists() && !directory.mkdirs()) { throw new RuntimeException("Cannot directory for holding the downloaded file: " + outputFile); } FileOutputStream outputTo = null; try { outputTo = new FileOutputStream(outputFile); Resources.copy(url, outputTo); } catch (FileNotFoundException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } finally { if (outputTo != null) { try { outputTo.close(); } catch (IOException e) { log.log(Level.WARNING, "Unable to close " + outputFile, e); } } } }
From source file:uk.ac.susx.tag.dependencyparser.Parser.java
public void evaluate(File goldStandard, String perlLocation, String dataFormat, String classifyOptions) throws IOException, InterruptedException { // This is the format that the eval script expects. final String requiredFormat = "id,form,ignore,ignore,pos,ignore,ignore,ignore,head,ignore,deprel,ignore,ignore,ignore"; File goldData = goldStandard; // If the data is not of this format, then create a temporary converted version if (!dataFormat.equals(requiredFormat)) { goldData = File.createTempFile("goldstandard", null); goldData.deleteOnExit();//ww w. j a v a 2 s.com // Note that we're careful to copy over the "ghead" and "gdeprel" (the gold standard versions, because by default, the CoNLLWriter assumes by "head" and "deprel" in the format string, that you mean the output of the parser; but the parser hasn't done anything yet, we're just copying over the gold standard data convert(goldStandard, dataFormat, goldData, requiredFormat); } // Copy the eval script to a temporary file ready for execution File evalScript = File.createTempFile("evalScript", null); evalScript.deleteOnExit(); // Ensure that temporary file is deleted once execution is completed. try (BufferedOutputStream modelStream = new BufferedOutputStream(new FileOutputStream(evalScript))) { Resources.copy(Resources.getResource("eval.pl"), modelStream); } // Create a temporary file to which we will write the parsed version of the data File parsedData = File.createTempFile("parsedData", null); parsedData.deleteOnExit(); // Parse the gold standard, writing out the results to the temporary file parseFile(goldData, parsedData, requiredFormat, classifyOptions); // Build command for execute evaluation script ProcessBuilder pb = new ProcessBuilder(perlLocation, evalScript.getAbsolutePath(), "-g", goldData.getAbsolutePath(), "-s", parsedData.getAbsolutePath()); // Redirect the output of the script to standard out of this parent process pb.redirectErrorStream(true); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); // Execute and wait for the script to finish before cleaning up temporary files Process p = pb.start(); p.waitFor(); // Explicitly try to delete temporary files, reporting any failures. if (!dataFormat.equals(requiredFormat) && !goldData.delete()) System.err .print("WARNING: temporary gold standard file was not deleted: " + goldData.getAbsolutePath()); if (!parsedData.delete()) System.err.print("WARNING: temporary parsed gold standard file was not deleted: " + parsedData.getAbsolutePath()); if (!evalScript.delete()) System.err.print("WARNING: temporary eval script was not deleted: " + evalScript.getAbsolutePath()); }