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.apache.sentry.provider.file.PolicyFiles.java
public static void copyToDir(File dest, String... resources) throws FileNotFoundException, IOException { for (String resource : resources) { LOGGER.info("Copying " + resource + " to " + dest); Resources.copy(Resources.getResource(resource), new FileOutputStream(new File(dest, resource))); }/*from w w w .j a v a2s .c o m*/ }
From source file:org.apache.sentry.core.common.utils.PolicyFiles.java
public static void copyToDir(File dest, String... resources) throws FileNotFoundException, IOException { for (String resource : resources) { LOGGER.debug("Copying " + resource + " to " + dest); Resources.copy(Resources.getResource(resource), new FileOutputStream(new File(dest, resource))); }/*from w w w. ja v a 2 s.c o m*/ }
From source file:fr.brouillard.oss.jgitver.cfg.ResourceConfigurationProvider.java
/** * Builds a {@link ResourceConfigurationProvider} object by saving the given resource as a "jgitver.config.xml" file * inside a newly created directory./*from www .j ava2s.c o m*/ * * @param configurationResource the resource to read as "jgitver.config.xml" content * @return a non null {@link ResourceConfigurationProvider} */ public static ResourceConfigurationProvider fromResource(String configurationResource) { File dir = com.google.common.io.Files.createTempDir(); try { File mvn = new File(dir, ".mvn"); mvn.mkdir(); File f = new File(mvn, "jgitver.config.xml"); final FileOutputStream fos = new FileOutputStream(f); Resources.copy(ResourceConfigurationProvider.class.getResource(configurationResource), fos); fos.close(); return new ResourceConfigurationProvider(dir); } catch (Exception ex) { try { deleteDirectory(dir); } catch (IOException ignore) { // cannot do anything } throw new IllegalStateException( "cannot create configuration directory for resource: " + configurationResource, ex); } }
From source file:sorcer.file.remote.WebFile.java
@Override protected File doGetFile() throws IOException { File localFile = getLocalPath(); try (FileOutputStream local = new FileOutputStream(localFile)) { Resources.copy(remoteUrl, local); }//from www.ja v a 2s.com return localFile; }
From source file:org.killbill.billing.osgi.http.StaticServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final URL url = findResourceURL(req); if (url != null) { Resources.copy(url, resp.getOutputStream()); resp.setStatus(200);/*ww w . j ava 2s. c o m*/ return; } // If we can't find it, the container might final RequestDispatcher rd = getServletContext().getNamedDispatcher("default"); final HttpServletRequest wrapped = new HttpServletRequestWrapper(req) { public String getServletPath() { return ""; } }; rd.forward(wrapped, resp); }
From source file:org.asciidoctor.asciidoclet.Stylesheets.java
public boolean copy() { if (!docletOptions.destDir().isPresent()) { // standard doclet must have checked this by the time we are called errorReporter.printError("Destination directory not specified, cannot copy stylesheet"); return false; }/*from w w w .j ava2 s .co m*/ String stylesheet = selectStylesheet(System.getProperty("java.version")); File destDir = docletOptions.destDir().get(); try { Resources.copy(Resources.getResource(stylesheet), new FileOutputStream(new File(destDir, OUTPUT_STYLESHEET))); Resources.copy(Resources.getResource(CODERAY_STYLESHEET), new FileOutputStream(new File(destDir, CODERAY_STYLESHEET))); return true; } catch (IOException e) { errorReporter.printError(e.getLocalizedMessage()); return false; } }
From source file:org.openqa.selenium.internal.seleniumemulation.AttachFile.java
private File downloadFile(String name) { URL url = getUrl(name);// ww w .j a va 2s .c o m File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("attachFile", "dir"); File outputTo = new File(dir, url.getFile()); if (!outputTo.getParentFile().mkdirs()) { throw new SeleniumException("Cannot create file for upload: " + outputTo); } FileOutputStream fos = null; try { fos = new FileOutputStream(outputTo); Resources.copy(url, fos); } catch (IOException e) { } return outputTo; }
From source file:org.openqa.selenium.firefox.ClasspathExtension.java
@Override public void writeTo(File extensionsDir) throws IOException { if (!FileHandler.isZipped(loadFrom)) { throw new WebDriverException("Will only install zipped extensions for now"); }/* w w w . j av a2s . co m*/ File holdingPen = new File(extensionsDir, "webdriver-staging"); FileHandler.createDir(holdingPen); File extractedXpi = new File(holdingPen, loadFrom); File parentDir = extractedXpi.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); } URL resourceUrl = Resources.getResource(loadResourcesUsing, loadFrom); try (OutputStream stream = new FileOutputStream(extractedXpi)) { Resources.copy(resourceUrl, stream); } new FileExtension(extractedXpi).writeTo(extensionsDir); }
From source file:ws.moor.swissvault.servlets.HomePageServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // see rfc6797 for explanation of header resp.addHeader("Strict-Transport-Security", "max-age=7776000; includeSubDomains"); // 90 days if (userIdProvider.get().isPresent()) { resp.setContentType("text/html"); resp.setCharacterEncoding("utf-8"); Resources.copy(mainPageResourceUrl, resp.getOutputStream()); } else {/* w w w . ja v a 2 s .c o m*/ resp.sendRedirect(authHelper.createRedirectUri().toString()); } }
From source file:co.cask.cdap.internal.app.runtime.batch.distributed.ContainerLauncherGenerator.java
/** * Generates a JAR file for launching MapReduce containers. The generated jar contains three classes inside * * <ul>// w ww. j av a 2 s .c o m * <li>{@link MRAppMaster}</li> * <li>{@link org.apache.hadoop.mapred.YarnChild YarnChild}</li> * <li>{@link MapReduceContainerLauncher}</li> * </ul> * * @see MapReduceContainerLauncher */ public static void generateLauncherJar(String launcherClassPath, String classLoaderName, OutputSupplier<? extends OutputStream> outputSupplier) throws IOException { try (JarOutputStream output = new JarOutputStream(outputSupplier.getOutput())) { generateLauncherClass(launcherClassPath, classLoaderName, MRAppMaster.class.getName(), output); generateLauncherClass(launcherClassPath, classLoaderName, "org.apache.hadoop.mapred.YarnChild", output); // Includes the launcher class in the JAR as well. No need to trace dependency as the launcher // class must be dependency free. String containerLauncherName = Type.getInternalName(MapReduceContainerLauncher.class) + ".class"; output.putNextEntry(new JarEntry(containerLauncherName)); URL launcherURL = ContainerLauncherGenerator.class.getClassLoader().getResource(containerLauncherName); // Can never be null Preconditions.checkState(launcherURL != null); Resources.copy(launcherURL, output); } }