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.geogit.api.porcelain.InitOp.java
private void copyHookFile(String folder, String file) throws IOException { URL url = Resources.getResource("org/geogit/api/hooks/" + file); OutputStream os = new FileOutputStream(new File(folder, file).getAbsolutePath()); Resources.copy(url, os); os.close();/* w w w .j a va2 s. com*/ }
From source file:com.bsiag.htmltools.internal.PublishUtility.java
private static void copyNavImg(File htmlFolder) throws IOException { File toFolder = new File(htmlFolder, IMAGES_SUB_PATH); toFolder.mkdirs();/*from w w w . ja va 2s. c o m*/ Resources.copy(Resources.getResource("nav_images/" + IMAGE_HOME), new FileOutputStream(new File(toFolder, IMAGE_HOME))); Resources.copy(Resources.getResource("nav_images/" + IMAGE_NEXT), new FileOutputStream(new File(toFolder, IMAGE_NEXT))); Resources.copy(Resources.getResource("nav_images/" + IMAGE_PREV), new FileOutputStream(new File(toFolder, IMAGE_PREV))); }
From source file:org.prebake.service.tools.ext.JunitHtmlReportGenerator.java
static void generateHtmlReport(Map<String, ?> jsonReport, Path reportDir) throws IOException { // Group tests by packages so we can let users examine the results by // logical groupings. ImmutableMultimap<String, Map<?, ?>> byPackage; List<String> resultTypes; {/*from w w w.j a v a2 s .co m*/ Set<String> resultTypeSet = Sets.newHashSet(); ImmutableList.Builder<Map<?, ?>> b = ImmutableList.builder(); // We can't trust the jsonReport to have the same structure as the method // above, since a filter could arbitrarily change it. Object tests = jsonReport.get(ReportKey.TESTS); if (tests instanceof Iterable<?>) { for (Object testVal : (Iterable<?>) tests) { if (!(testVal instanceof Map<?, ?>)) { continue; // If filter nulls out elements. } Map<?, ?> test = (Map<?, ?>) testVal; b.add(test); String result = getIfOfType(test, ReportKey.RESULT, String.class); resultTypeSet.add(result); } } byPackage = groupBy(b.build(), new Function<Map<?, ?>, String>() { public String apply(Map<?, ?> test) { String className = getIfOfType(test, ReportKey.CLASS_NAME, String.class); if (className == null) { return null; } int lastDot = className.lastIndexOf('.'); return (lastDot >= 0) ? className.substring(0, lastDot) : ""; } }); String[] resultTypeArr = resultTypeSet.toArray(NO_STRINGS); Arrays.sort(resultTypeArr); resultTypes = ImmutableList.copyOf(resultTypeArr); } Map<String, Integer> summary = Maps.newHashMap(); ImmutableList.Builder<Html> table = ImmutableList.builder(); // Now, call out to create the package groupings, which in turn, // create the class level groupings, which in turn create pages for // individual tests. // As we descend into the test tree, each recursive call updates summary // info. Path outFile = reportDir.resolve("index.html"); mkdirs(outFile.getParent()); String[] packageNames = byPackage.keySet().toArray(NO_STRINGS); Arrays.sort(packageNames); for (String packageName : packageNames) { Collection<Map<?, ?>> tests = byPackage.get(packageName); Map<String, Integer> itemSummary = generateHtmlReportOnePackage(packageName, tests, reportDir.resolve("index"), resultTypes); bagPutAll(itemSummary, summary); table.add(htmlLink("index/" + packageName + PACKAGE_FILE_SUFFIX + ".html", packageName)) .add(htmlSpan("summary", summaryToHtml(itemSummary, resultTypes))); } writeReport(outFile, "JUnit", KEY_VAL, table.build(), summary, jsonReport, resultTypes, "index"); OutputStream out = reportDir.resolve("junit_report.css").newOutputStream(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); try { Resources.copy(Resources.getResource(JunitHtmlReportGenerator.class, "junit_report.css"), out); } finally { out.close(); } }
From source file:com.google.devtools.moe.client.SystemFileSystem.java
@Override public File getResourceAsFile(String resource) throws IOException { String name = (new File(resource)).getName(); if (name.isEmpty()) { throw new IOException("Invalid resource name: " + resource); }/*from ww w . j av a 2 s . co m*/ File extractedFile = new File(getTemporaryDirectory("resource_extraction_", Lifetimes.moeExecution()), name); makeDirsForFile(extractedFile); OutputStream os = Files.asByteSink(extractedFile).openStream(); Resources.copy(SystemFileSystem.class.getResource(resource), os); os.close(); return extractedFile; }
From source file:org.geogig.geoserver.config.LogStoreInitializer.java
static void copySampleInitSript(File configDirectory, String scriptName) throws IOException { File file = new File(configDirectory, scriptName); if (file.exists()) { return;//from w w w. ja v a 2 s .co m } file.createNewFile(); try (OutputStream out = new FileOutputStream(file)) { Resources.copy(LogStoreInitializer.class.getResource(scriptName), out); } }
From source file:uk.ac.susx.tag.dependencyparser.Parser.java
/** * Convenience method with same defaults as above except that the user can specify another index and model to be * found in the jar's resources. The index file is expected to be in the resources folder with name: * parserName+"-index", and the model with name: parserName+"-model". *//*w ww .java 2 s . c o m*/ public Parser(String parserName, SelectionMethod method) throws IOException { // Create a temporary file, into which we will stream the classifier model from JAR resources. File model = File.createTempFile("model", null); model.deleteOnExit(); // Ensure that temporary file is deleted once execution is completed. // Copy classifier model to temporary file try (BufferedOutputStream modelStream = new BufferedOutputStream(new FileOutputStream(model))) { Resources.copy(Resources.getResource(parserName + "-model"), modelStream); } // Get appropriate classifier instance and use it to load the model classifier = Options.getClassifier("linear-svm"); classifier.load(model); if (!model.delete()) System.err.print("WARNING: model temp file was not deleted: " + model.getAbsolutePath()); // Load and set index to read only this.index = Index.load(Resources.getResource(parserName + "-index").openStream()); this.index.setReadOnly(true); // Load feature table featureTable = new FeatureTable(Resources.getResource("feature_table.txt").openStream()); // Ascertain parse style parseStyle = Options.getParserStyle("arc-eager"); // Ascertain transition selection method selectionMethod = method; }
From source file:org.geogig.geoserver.config.LogStoreInitializer.java
private static List<String> parseStatements(URL script) { List<String> lines; try {/*from w w w .j a va 2 s .c o m*/ OutputStream to = new ByteArrayOutputStream(); Resources.copy(script, to); String scriptContents = to.toString(); lines = CharStreams.readLines(new StringReader(scriptContents)); } catch (IOException e) { throw Throwables.propagate(e); } List<String> statements = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); for (String line : lines) { line = line.trim(); if (line.startsWith("#") || line.startsWith("-") || line.isEmpty()) { continue; } sb.append(line).append('\n'); if (line.endsWith(";")) { statements.add(sb.toString()); sb.setLength(0); } } return statements; }
From source file:org.kiji.bento.tools.ConfigurationSetupTool.java
/** * Writes a clean XML configuration file. The file is written if it does not exist or the * user requested a reset./* w ww .j ava 2 s .c o m*/ * * @param directory is the directory the file should be written to. * @param confFileName is the filename of the clean configuration file to write. * @throws IOException if there is an error writing the file. */ private void maybeWriteConfFile(File directory, String confFileName) throws IOException { if (!isFileExists(directory, confFileName) || mResetConfiguration) { System.out.println("Writing clean " + confFileName); URL resourceUrl = Resources.getResource(RESOURCES_ROOT + confFileName); FileOutputStream out = null; try { out = new FileOutputStream(new File(directory, confFileName)); Resources.copy(resourceUrl, out); } finally { IOUtils.closeQuietly(out); } } }
From source file:org.locationtech.geogig.api.porcelain.InitOp.java
private void copyHookFile(String folder, String file) throws IOException { URL url = Resources.getResource(Hookables.class, file); OutputStream os = new FileOutputStream(new File(folder, file).getAbsolutePath()); Resources.copy(url, os); os.close();//from w ww . j a va 2 s. com }
From source file:org.r10r.doctester.rendermachine.RenderMachineImpl.java
private void copyResourceIfItExists(String resource, String targetFileForResource) { try {// ww w . j a v a2 s.c o m URL url = this.getClass().getClassLoader().getResource(resource); if (url == null) { logger.info("Did not find resource {}.", resource); return; } File targetFile = new File(targetFileForResource); Files.createParentDirs(targetFile); Resources.copy(url, new FileOutputStream(targetFile)); } catch (IOException ex) { logger.error("Something went wrong copying resource {}", resource, ex); } }