List of usage examples for com.google.common.io Resources getResource
public static URL getResource(Class<?> contextClass, String resourceName)
From source file:org.eclipse.scada.configuration.component.common.lib.Helper.java
static String loadResource(final String resourceName) { final URL updateUrl = Resources.getResource(Helper.class, resourceName); try {// w w w . j a v a 2 s. c om return Resources.toString(updateUrl, Charset.forName("UTF-8")); } catch (final IOException e) { throw new RuntimeException(String.format("Unable to load '%s'", resourceName), e); } }
From source file:br.com.objectos.testing.MoreAsserts.java
public static String toString(String name) { try {// ww w.j a v a2 s . co m URL url = Resources.getResource(MoreAsserts.class, name); return Resources.toString(url, Charsets.UTF_8); } catch (IOException e) { return ""; } }
From source file:org.sonar.plugins.pmd.PmdTestUtils.java
public static String getResourceContent(String path) { try {/*from w ww .j a v a 2s. c o m*/ return Resources.toString(Resources.getResource(PmdTestUtils.class, path), Charsets.UTF_8); } catch (IOException e) { throw new IllegalArgumentException("Could not load resource " + path, e); } }
From source file:br.com.objectos.office.writer.DocumentFake.java
private static File fileOf(String resourceName) { try {//from w w w.jav a2s .co m URL url = Resources.getResource(DocumentFake.class, resourceName); URI uri = url.toURI(); return new File(uri); } catch (URISyntaxException e) { throw Throwables.propagate(e); } }
From source file:google.registry.tldconfig.idn.IdnTableEnum.java
private static IdnTable load(String name) { try {// w w w .j a v a 2s . co m URL resource = Resources.getResource(IdnTableEnum.class, name + ".txt"); return IdnTable.createFrom(name, readLines(resource, UTF_8), LanguageValidator.get(name)); } catch (IOException e) { throw new RuntimeException(e); // should never happen } }
From source file:org.eclipse.scada.protocol.utils.BufferLoader.java
public static List<IoBuffer> loadBuffersFromResource(final Class<?> clazz, final String resourceName) throws IOException { logger.debug("Loading buffer - {}", resourceName); final URL url = Resources.getResource(clazz, resourceName); return Resources.readLines(url, Charset.forName("UTF-8"), new LineProcessor<List<IoBuffer>>() { private final List<IoBuffer> result = new LinkedList<>(); private IoBuffer buffer = null; protected void pushBuffer() { if (this.buffer == null) { return; }// www . j a v a 2 s.c o m this.buffer.flip(); this.result.add(this.buffer); this.buffer = null; } @Override public boolean processLine(String line) throws IOException { line = line.replaceAll("#.*", ""); // clear comments if (line.isEmpty()) { pushBuffer(); return true; } final String[] toks = line.split("\\s+"); if (toks.length <= 0) { pushBuffer(); return true; } if (this.buffer == null) { // start a new buffer this.buffer = IoBuffer.allocate(0); this.buffer.setAutoExpand(true); } for (final String tok : toks) { this.buffer.put(Byte.parseByte(tok, 16)); } return true; } @Override public List<IoBuffer> getResult() { pushBuffer(); // last chance to add something return this.result; } }); }
From source file:org.sonar.plugins.checkstyle.CheckstyleTestUtils.java
public static String getResourceContent(String path) { try {//from w ww . j a va 2 s. c o m return Resources.toString(Resources.getResource(CheckstyleTestUtils.class, path), Charsets.UTF_8); } catch (IOException e) { throw new IllegalArgumentException("Could not load resource " + path, e); } }
From source file:com.facebook.hiveio.common.NativeCodeHelper.java
/** * Load a library/*from w w w.ja v a 2s . c om*/ * * @param name String name of library * @throws IOException */ protected static void loadLibrary(String name) throws IOException { URL url = Resources.getResource(HadoopNative.class, getLibraryPath(name)); File file = File.createTempFile(name, null); file.deleteOnExit(); Files.copy(Resources.newInputStreamSupplier(url), file); System.load(file.getAbsolutePath()); }
From source file:ch.ethz.system.mt.tpch.Distributions.java
public static synchronized Distributions getDefaultDistributions() { if (DEFAULT_DISTRIBUTIONS == null) { try {//from ww w . j a va 2 s. c om URL resource = Resources.getResource(Distribution.class, "dists.dss"); checkState(resource != null, "Distribution file 'dists.dss' not found"); DEFAULT_DISTRIBUTIONS = new Distributions( loadDistribution(Resources.asCharSource(resource, Charsets.UTF_8))); } catch (IOException e) { throw Throwables.propagate(e); } } return DEFAULT_DISTRIBUTIONS; }
From source file:org.arkhamnetwork.playersync.managers.SQLManager.java
private static void setupSQLTables() throws IOException, SQLException { URL resource = Resources.getResource(PlayerSync.class, "/tables.sql"); String[] databaseStructure = Resources.toString(resource, Charsets.UTF_8).split(";"); if (databaseStructure.length == 0) { return;/*from ww w .j a v a 2 s . com*/ } 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(); } } }