List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:com.eucalyptus.simplequeue.persistence.cassandra.CassandraSessionManager.java
private static void createSchema(final Session session) { // create new keyspace/tables (should not do here) TODO: move session.execute("CREATE KEYSPACE IF NOT EXISTS eucalyptus_simplequeue " + "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}; "); session.execute("USE eucalyptus_simplequeue;"); try {/*from w w w . java 2 s. com*/ final String cql = Resources.toString( Resources.getResource("2017-03-03-eucalyptus-simplequeue-base.cql"), StandardCharsets.UTF_8); CqlUtil.splitCql(cql).forEach(session::execute); } catch (final IOException | ParseException e) { throw Exceptions.toUndeclared(e); } }
From source file:com.selesse.tailerswift.gui.view.AboutFrame.java
private String getOpenSourceLicenseText() { String licenseText = ""; URL guavaUrl = Resources.getResource("licenses/guava.txt"); URL slf4jUrl = Resources.getResource("licenses/slf4j.txt"); try {//ww w .ja v a2 s . c o m String guavaContents = Resources.toString(guavaUrl, Charsets.UTF_8); String slf4jContents = Resources.toString(slf4jUrl, Charsets.UTF_8); licenseText = guavaContents + "\n\n" + slf4jContents; } catch (IOException e) { LOGGER.error("Could not open license", e); } return licenseText; }
From source file:org.apache.omid.YAMLUtils.java
@SuppressWarnings("unchecked") private Map loadAsMap(String path) throws IOException { try {//from www . j a v a2 s. com String content = Resources.toString(Resources.getResource(path), Charset.forName("UTF-8")); LOG.debug("Loaded resource file '{}'\n{}", path, content); Map settings = new Yaml().loadAs(content, Map.class); if (settings == null) { settings = new HashMap(0); } return settings; } catch (IllegalArgumentException e) { return new HashMap(); } }
From source file:com.google.javascript.refactoring.RefasterJsScanner.java
/** * Loads the RefasterJs template. This must be called before the scanner is used. *///from w w w . ja v a 2 s . c o m public void loadRefasterJsTemplate(String refasterjsTemplate) throws IOException { Preconditions.checkState(templateJs == null, "Can't load RefasterJs template since a template is already loaded."); this.templateJs = Thread.currentThread().getContextClassLoader().getResource(refasterjsTemplate) != null ? Resources.toString(Resources.getResource(refasterjsTemplate), UTF_8) : Files.toString(new File(refasterjsTemplate), UTF_8); }
From source file:org.arkhamnetwork.uuid.ArkhamUUIDLogger.java
private void setupSQLTables() throws IOException, SQLException { URL resource = Resources.getResource(ArkhamUUIDLogger.class, "/tables.sql"); String[] databaseStructure = Resources.toString(resource, Charsets.UTF_8).split(";"); if (databaseStructure.length == 0) { return;/*from w w w. ja v a 2 s. c o m*/ } Statement statement = null; try { C.setAutoCommit(false); statement = C.createStatement(); for (String query : databaseStructure) { query = query.trim(); if (query.isEmpty()) { continue; } statement.execute(query); } C.commit(); } finally { C.setAutoCommit(true); if (statement != null && !statement.isClosed()) { statement.close(); } } }
From source file:com.github.lightdocs.processor.DocumentedByAnnotationProcessor.java
private String loadScript(String resPath) { String script;// w ww . j a v a 2s . c o m try { URL resUrl; if (resPath.toLowerCase().startsWith("http://") || resPath.toLowerCase().startsWith("file://")) { resUrl = new URL(resPath); } else { resUrl = getClass().getResource(resPath); } script = Resources.toString(resUrl, Charsets.UTF_8); } catch (Exception e) { throw new RuntimeException(e); } return script; }
From source file:org.jsfr.json.BenchmarkParseLargeJsonWithoutStreaming.java
@Setup public void setup() throws IOException { gson = new GsonBuilder().create(); om = new ObjectMapper(); json = Resources.toString(Resources.getResource("allthethings.json"), StandardCharsets.UTF_8); }
From source file:io.prestosql.plugin.cassandra.EmbeddedCassandra.java
private static String prepareCassandraYaml() throws IOException { String original = Resources.toString(getResource("cu-cassandra.yaml"), UTF_8); File tempDirFile = createTempDir(); tempDirFile.deleteOnExit();/*w ww . ja va 2s . c o m*/ Path tmpDirPath = tempDirFile.toPath(); Path dataDir = tmpDirPath.resolve("data"); Files.createDirectory(dataDir); String modified = original.replaceAll("\\$\\{data_directory\\}", dataDir.toAbsolutePath().toString()); Path yamlLocation = tmpDirPath.resolve("cu-cassandra.yaml"); write(modified, yamlLocation.toFile(), UTF_8); return yamlLocation.toAbsolutePath().toString(); }
From source file:com.facebook.buck.python.PythonInPlaceBinary.java
private static String getRunInplaceResource() { try {/*from w w w . j a v a 2 s . com*/ return Resources.toString(Resources.getResource(RUN_INPLACE_RESOURCE), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.sk89q.worldedit.world.registry.BundledItemData.java
/** * Attempt to load the data from file./*w w w . ja va2 s.c o m*/ * * @throws IOException thrown on I/O error */ private void loadFromResource() throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.create(); URL url = BundledItemData.class.getResource("items.json"); if (url == null) { throw new IOException("Could not find items.json"); } String data = Resources.toString(url, Charset.defaultCharset()); List<ItemEntry> entries = gson.fromJson(data, new TypeToken<List<ItemEntry>>() { }.getType()); for (ItemEntry entry : entries) { idMap.put(entry.id, entry); } }