List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.google.gapid.views.Licenses.java
protected static String readLicenses(boolean html) { try {//w w w. ja va2s.co m String result = Resources.toString(Resources.getResource("text/licenses.html"), UTF_8); if (html) { // Linkify links. result = result.replaceAll("(https?://[^\\s]+(?:[^\\s.,;:!?'\"()\\[\\]{}]))", "<a href='$1'>$1</a>"); } else { // De-HTML the text. result = result.replaceAll("<[^>]+>", ""); } return result; } catch (IOException | IllegalArgumentException e) { LOG.log(SEVERE, "Failed to load the licenses", e); return "Failed to load the licenses."; } }
From source file:com.huangyunkun.jviff.core.impl.HtmlResultReport.java
private void copyResources(File outputDir) throws IOException { String frontFolder = Resources.getResource("static").getFile(); FileUtils.copyDirectory(new File(frontFolder), new File(outputDir, "static")); }
From source file:org.apache.drill.exec.store.ClassPathFileSystem.java
@Override public FileStatus getFileStatus(Path arg0) throws IOException { String file = getFileName(arg0); URL url;/* w ww . j a va 2 s . c om*/ try { url = Resources.getResource(file); } catch (IllegalArgumentException e) { throw new FileNotFoundException(String.format("Unable to find path %s.", arg0.toString())); } return new FileStatus(Resources.asByteSource(url).size(), false, 1, 8096, System.currentTimeMillis(), arg0); }
From source file:com.torodb.DefaultBuildProperties.java
public DefaultBuildProperties(String propertiesFile) { PropertiesConfiguration properties;//from w w w.j av a 2 s. c o m try { properties = new PropertiesConfiguration(Resources.getResource(propertiesFile)); } catch (ConfigurationException e) { throw new RuntimeException("Cannot read build properties file '" + propertiesFile + "'"); } fullVersion = properties.getString("version"); Matcher matcher = FULL_VERSION_PATTERN.matcher(fullVersion); if (!matcher.matches()) { throw new RuntimeException("Invalid version string '" + fullVersion + "'"); } majorVersion = Integer.parseInt(matcher.group(1)); minorVersion = Integer.parseInt(matcher.group(2)); subVersion = matcher.group(3) != null ? Integer.parseInt(matcher.group(3)) : 0; extraVersion = matcher.group(4); // DateUtils.parseDate may be replaced by SimpleDateFormat if using Java7 try { buildTime = DateUtils.parseDate(properties.getString("buildTimestamp"), new String[] { ISO8601_FORMAT_STRING }); } catch (ParseException e) { throw new RuntimeException("buildTimestamp property not in ISO8601 format"); } gitCommitId = properties.getString("gitCommitId"); gitBranch = properties.getString("gitBranch"); gitRemoteOriginURL = properties.getString("gitRemoteOriginURL"); javaVersion = properties.getString("javaVersion"); javaVendor = properties.getString("javaVendor"); javaVMSpecificationVersion = properties.getString("javaVMSpecificationVersion"); javaVMVersion = properties.getString("javaVMVersion"); osName = properties.getString("osName"); osArch = properties.getString("osArch"); osVersion = properties.getString("osVersion"); }
From source file:org.hawkular.metrics.clients.ptrans.exec.ExecutableITestBase.java
@Before public void before() throws Exception { ptransConfFile = temporaryFolder.newFile(); try (FileOutputStream out = new FileOutputStream(ptransConfFile)) { Resources.copy(Resources.getResource("ptrans.conf"), out); }/*w w w.ja v a 2s. c o m*/ ptransOut = temporaryFolder.newFile(); ptransErr = temporaryFolder.newFile(); ptransPidFile = temporaryFolder.newFile(); ptransProcessBuilder = new ProcessBuilder(); ptransProcessBuilder.directory(temporaryFolder.getRoot()); ptransProcessBuilder.redirectOutput(ptransOut); ptransProcessBuilder.redirectError(ptransErr); ptransProcessBuilder.command(JAVA, "-Xss228k", "-jar", PTRANS_ALL); }
From source file:io.airlift.rack.RackServlet.java
@Inject public RackServlet(RackServletConfig config) throws IOException { Preconditions.checkNotNull(config);/* w w w .ja v a 2s . c o m*/ File rackScriptFile = new File(config.getRackConfigPath()); Preconditions.checkArgument(rackScriptFile.canRead(), "Could not find rack script specified by [" + config.getRackConfigPath() + "] and resolved to [" + rackScriptFile.getAbsolutePath() + "]"); runtime = JavaEmbedUtils.initialize(ImmutableList.of(rackScriptFile.getParentFile().getCanonicalPath()), createRuntimeConfig()); // don't inherit system settings for gems RubyHash env = runtime.evalScriptlet("ENV").convertToHash(); env.remove("GEM_HOME"); env.remove("GEM_PATH"); InputStream stream = Resources.getResource("io/airlift/rack.rb").openStream(); try { runtime.loadFile("rack.rb", stream, false); } finally { stream.close(); } IRubyObject builder = runtime.evalScriptlet("Airlift::RackServer::Builder.new"); rackApplication = adapter.callMethod(builder, "build", new IRubyObject[] { javaToRuby(runtime, rackScriptFile.getCanonicalPath()) }); }
From source file:talkeeg.dc.ui.GuiManager.java
protected void loadIconImage() { try {/*from w w w . j a va2 s . c o m*/ icon = ImageIO.read(Resources.getResource("icon_24.png")); } catch (IOException | IllegalArgumentException e) { //init default image, otherwise tray icon initialization will be failed icon = new BufferedImage(16, 16, BufferedImage.TYPE_BYTE_BINARY); } }
From source file:org.n52.youngs.impl.SourceRecordHelper.java
public static SourceRecord getSourceRecordFromFile(String filename) throws Exception { try (InputStream is = Resources.asByteSource(Resources.getResource(filename)).openStream();) { DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = documentBuilder.parse(is); Element elem = doc.getDocumentElement(); elem.normalize();/*from w w w . j ava 2 s .com*/ NodeSourceRecord record = new NodeSourceRecord(elem); return record; } }
From source file:de.vonengel.g930beat.Heartbeat.java
private URL getFileUrl() throws MalformedURLException { Path path = Paths.get(preferences.getFile()); if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) { return path.toUri().toURL(); }//from ww w. j a va2 s . c o m return Resources.getResource(preferences.getFile()); }
From source file:com.streamsets.datacollector.flume.standalone.FlumeDestinationPipelineOperationsIT.java
private static String getPipelineJson() throws Exception { URI uri = Resources.getResource("flume_destination_pipeline_operations.json").toURI(); String pipelineJson = new String(Files.readAllBytes(Paths.get(uri)), StandardCharsets.UTF_8); return pipelineJson; }