List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:blue.lapis.methodremapper.RemapperConfig.java
/** * Loads the mappings from the specified {@link File} or resource. If a file * using the specified name exists, it will be loaded from the file. If not, * it will be loaded as resource from the JAR. * * @param name The name of the file to load the mappings from * @return The loaded mappings// w ww .j ava 2 s . com * @throws IOException If the mappings couldn't be loaded */ public static ImmutableTable<String, String, String> loadMappings(String name) throws IOException { File file = new File(name); if (file.exists()) { return loadMappings(file); } return loadMappings(Resources.getResource(name)); }
From source file:com.gwtplatform.dispatch.rest.rebind.DispatchRestRebindModule.java
@Provides @Singleton/*from w w w. j a v a 2s.c o m*/ @VelocityProperties Properties getVelocityProperties(Logger logger) throws UnableToCompleteException { Properties properties = new Properties(); try { URL url = Resources.getResource(VELOCITY_PROPERTIES); ByteSource byteSource = Resources.asByteSource(url); properties.load(byteSource.openStream()); } catch (Exception e) { logger.die("Unable to load velocity properties from '%s'.", e, VELOCITY_PROPERTIES); } return properties; }
From source file:org.graylog2.fongo.SeedingFongoRule.java
public void insertSeed(String seed) throws IOException { final byte[] bytes = Resources.toByteArray(Resources.getResource(seed)); final Map<String, Object> map = objectMapper.readValue(bytes, MAP_TYPE); for (String collectionName : map.keySet()) { @SuppressWarnings("unchecked") final List<Map<String, Object>> documents = (List<Map<String, Object>>) map.get(collectionName); final MongoCollection<Document> indexSets = getDatabase().getCollection(collectionName); for (Map<String, Object> document : documents) { final Document parsedDocument = Document.parse(objectMapper.writeValueAsString(document)); LOG.debug("Inserting parsed document: \n{}", parsedDocument.toJson(new JsonWriterSettings(true))); indexSets.insertOne(parsedDocument); }/*from w w w.j av a 2s .co m*/ } }
From source file:com.streamsets.datacollector.http.LdapAuthenticationBaseIT.java
static LdapConnection setupLdapServer(GenericContainer server, String setupFile) { // setup Ldap server 1 LdapConnection connection = new LdapNetworkConnection(server.getContainerIpAddress(), server.getMappedPort(LDAP_PORT)); try {//from w w w. ja v a 2 s .co m connection.bind(BIND_DN, BIND_PWD); LdifReader reader = new LdifReader(Resources.getResource(setupFile).getFile()); for (LdifEntry entry : reader) { connection.add(entry.getEntry()); } } catch (LdapException e) { LOG.error("Setup server 1 failed " + e); } return connection; }
From source file:org.thingsboard.server.transport.mqtt.MqttSslHandlerProvider.java
public SslHandler getSslHandler() { try {//from w w w. java 2s .c o m URL ksUrl = Resources.getResource(keyStoreFile); File ksFile = new File(ksUrl.toURI()); URL tsUrl = Resources.getResource(keyStoreFile); File tsFile = new File(tsUrl.toURI()); TrustManagerFactory tmFactory = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); KeyStore trustStore = KeyStore.getInstance(keyStoreType); try (InputStream tsFileInputStream = new FileInputStream(tsFile)) { trustStore.load(tsFileInputStream, keyStorePassword.toCharArray()); } tmFactory.init(trustStore); KeyStore ks = KeyStore.getInstance(keyStoreType); try (InputStream ksFileInputStream = new FileInputStream(ksFile)) { ks.load(ksFileInputStream, keyStorePassword.toCharArray()); } KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(ks, keyPassword.toCharArray()); KeyManager[] km = kmf.getKeyManagers(); TrustManager x509wrapped = getX509TrustManager(tmFactory); TrustManager[] tm = { x509wrapped }; if (StringUtils.isEmpty(sslProtocol)) { sslProtocol = "TLS"; } SSLContext sslContext = SSLContext.getInstance(sslProtocol); sslContext.init(km, tm, null); SSLEngine sslEngine = sslContext.createSSLEngine(); sslEngine.setUseClientMode(false); sslEngine.setNeedClientAuth(false); sslEngine.setWantClientAuth(true); sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); sslEngine.setEnableSessionCreation(true); return new SslHandler(sslEngine); } catch (Exception e) { log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e); throw new RuntimeException("Failed to get SSL handler", e); } }
From source file:org.jsfr.json.BenchmarkParseLongText.java
@Setup public void setup() throws Exception { gsonSurfer = JsonSurfer.gson();//from w ww. j a va 2 s . com jacksonSurfer = JsonSurfer.jackson(); simpleSurfer = JsonSurfer.simple(); collectOneListener = new CollectOneListener(true); surfingConfiguration = SurfingConfiguration.builder().bind("$.findMe", collectOneListener).build(); gson = new GsonBuilder().create(); om = new ObjectMapper(); json = Resources.toString(Resources.getResource("longText.json"), StandardCharsets.UTF_8); }
From source file:com.ning.killbill.generators.ruby.JRubyPluginGenerator.java
private void generateStaticClass(final String className, final File outputDir) throws GeneratorException { OutputStream out = null;/*from w w w. j a v a2 s. c o m*/ try { final String resourceName = createFileName(className, true); final URL classUrl = Resources.getResource(resourceName); final File output = new File(outputDir, resourceName); out = new FileOutputStream(output); Resources.copy(classUrl, out); } catch (IOException e) { throw new GeneratorException("Failed to generate file " + className, e); } finally { if (out != null) { try { out.close(); } catch (IOException ignore) { } } } }
From source file:com.madvay.tools.android.perf.apat.Main.java
private static void printVersion() { outln(String.format("apat Version %s\n Built at %s\n On commit %s\n Url: %s", BuildInfo.VERSION, BuildInfo.TIMESTAMP, BuildInfo.GIT_COMMIT, BuildInfo.URL)); if (BuildInfo.VERSION.contains("SNAPSHOT")) { outln("*** Note: This is an unofficial snapshot release."); outln("*** See https://madvay.com/source/apat for official releases."); }/* w w w . j av a 2 s . c om*/ if (!BuildInfo.GIT_IS_CLEAN) { outln("!!! Warning: This unofficial build was made with local modifications."); outln("!!! See https://madvay.com/source/apat for official releases."); } outln("---------------------------------------------------------------"); try { List<String> lines = Resources.readLines(Resources.getResource("NOTICE"), Charsets.UTF_8); for (String l : lines) { outln(l); } } catch (IOException err) { err(err); } }
From source file:pl.coffeepower.blog.examples.LicenseWordsAnalyzer.java
public LicenseWordsAnalyzer() throws IOException { this.tokenizer = new TokenizerME(new TokenizerModel(Resources.getResource(TOKEN_MODEL))); }
From source file:eu.redzoo.article.planetcassandra.reactive.CassandraDB.java
/** * executes a CQL file /*from w w w . j ava2 s. c o m*/ * * @param cqlFile the CQL file name * @throws IOException if the file could not be found */ public void executeCqlFile(String cqlFile) throws IOException { File file = new File(cqlFile); if (file.exists()) { executeCql(Files.toString(new File(cqlFile), Charsets.UTF_8)); } else { executeCql(Resources.toString(Resources.getResource(cqlFile), Charsets.UTF_8)); } }