List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:org.apache.hive.ptest.execution.Templates.java
public static String readResource(String resource) throws IOException { return Resources.toString(Resources.getResource(resource), Charsets.UTF_8); }
From source file:org.kitesdk.data.filesystem.DatasetTestUtilities.java
private static Schema loadSchema(String resource) { try {//from w w w .j a v a 2 s . com return new Schema.Parser().parse(Resources.getResource(resource).openStream()); } catch (IOException e) { throw new IllegalStateException("Cannot load " + resource); } }
From source file:com.github.lukaszkusek.xml.comparator.util.ResourceReader.java
public static URL getURL(final String fileName) { return Resources.getResource("com/github/lukaszkusek/xml/comparator/" + fileName); }
From source file:org.jclouds.openstack.nova.live.PropertyHelper.java
public static Map<String, String> setupKeyPair(Properties properties) throws FileNotFoundException, IOException { return ImmutableMap.<String, String>of("private", Resources.toString(Resources.getResource(properties.getProperty("test.ssh.keyfile.private")), Charsets.UTF_8),// w ww. jav a 2 s. c o m "public", Resources.toString( Resources.getResource(properties.getProperty("test.ssh.keyfile.public")), Charsets.UTF_8)); }
From source file:se.kth.karamel.client.api.CookbookCacheImplIT.java
@Ignore public void testLoadCookbooks() throws IOException, KaramelException { CookbookCacheIml cache = new CookbookCacheIml(); String ymlString = Resources.toString( Resources.getResource("se/kth/karamel/client/model/test-definitions/hopsworks_compact.yml"), Charsets.UTF_8);/*w ww. j a v a 2 s . c o m*/ YamlCluster cluster = ClusterDefinitionService.yamlToYamlObject(ymlString); List<KaramelizedCookbook> all = cache.loadAllKaramelizedCookbooks(cluster); for (KaramelizedCookbook kc : all) { System.out.println(kc.getUrls().id); } }
From source file:guipart.view.Utils.java
static BufferedReader open(String inputFile) throws IOException { InputStream in;//from w ww .j av a2 s.c om try { in = Resources.getResource(inputFile).openStream(); } catch (IllegalArgumentException e) { in = new FileInputStream(new File(inputFile)); } return new BufferedReader(new InputStreamReader(in, Charsets.UTF_8)); }
From source file:com.fitbur.core.config.util.ResourceService.java
public URL getResource(String resource) { return Resources.getResource(resource); }
From source file:com.cognifide.qa.bb.aem.touch.util.YamlReader.java
/** * Reads yaml configuration file under given path and returns structure defined in type reference. * * @param path path to yaml configuration file. * @param typeReference type reference which will be used to construct result. * @return type reference defined structure of read yaml configuration file. *//*from ww w. jav a 2 s . c o m*/ public static <T> T read(String path, TypeReference typeReference) { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); try { URI uri = Resources.getResource(path + YAML).toURI(); File file = Paths.get(uri).toFile(); return mapper.readValue(file, typeReference); } catch (IOException | URISyntaxException e) { LOG.error("Could not read YAML file: {}", path); throw new IllegalStateException("YAML file could not be read"); } }
From source file:keywhiz.service.crypto.CryptoFixtures.java
/** @return a content cryptographer initialized with the testing derivation key. */ public static ContentCryptographer contentCryptographer() { if (cryptographer != null) { return cryptographer; }//from w w w . j av a 2 s. co m Provider provider = new BouncyCastleProvider(); if (Security.getProvider(provider.getName()) == null) { Security.addProvider(provider); } SecretKey baseKey; char[] password = "CHANGE".toCharArray(); try (InputStream in = Resources.getResource("derivation.jceks").openStream()) { KeyStore keyStore = KeyStore.getInstance("JCEKS"); keyStore.load(in, password); baseKey = (SecretKey) keyStore.getKey("basekey", password); } catch (CertificateException | UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | IOException e) { throw Throwables.propagate(e); } cryptographer = new ContentCryptographer(baseKey, provider, provider, FakeRandom.create()); return cryptographer; }
From source file:com.basistech.rosette.dm.test.OsgiTestUtil.java
/** * Assume that a test has a dependencies.properties in the classpath, and use it to retrieve the version. * @param groupId maven group id/* w w w. j a v a2 s. com*/ * @param artifactId maven artifact id * @return the version string */ public static String getDependencyVersion(String groupId, String artifactId) { URL depPropsUrl = Resources.getResource("META-INF/maven/dependencies.properties"); Properties depProps = new Properties(); try { depProps.load(Resources.asByteSource(depPropsUrl).openStream()); } catch (IOException e) { throw new RuntimeException(e); } String ver = (String) depProps.get(String.format("%s/%s/version", groupId, artifactId)); if (ver == null) { throw new RosetteRuntimeException(String.format("No version available for %s:%s", groupId, artifactId)); } ver = ver.replace("-SNAPSHOT", ".SNAPSHOT"); return ver; }