List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:org.icgc.dcc.submission.sftp.SftpBanner.java
@SneakyThrows private static String getBanner() { return Resources.toString(getResource(BANNER_FILE), UTF_8); }
From source file:com.optimizely.ab.event.internal.serializer.SerializerTestUtils.java
static String generateConversionWithSessionIdJson() throws IOException { String conversionJson = Resources.toString(Resources.getResource("serializer/conversion-session-id.json"), Charsets.UTF_8);//from w ww .j a v a 2 s . c om return conversionJson.replaceAll("\\s+", ""); }
From source file:com.sequenceiq.cloudbreak.conf.ApiDocConfig.java
private ApiInfo apiInfo() throws IOException { URL url = Resources.getResource("swagger/cloudbreak-introduction"); ApiInfo apiInfo = new ApiInfo("Cloudbreak API", Resources.toString(url, Charsets.UTF_8), "https://www.apache.org/licenses/LICENSE-2.0.html", "info@sequenceiq.com", "Apache 2.0", "https://www.apache.org/licenses/LICENSE-2.0.html"); return apiInfo; }
From source file:li.klass.fhem.domain.core.DeviceXMLParsingBase.java
protected void mockStrings() { try {// w ww. j ava 2s .c o m String content = Resources.toString( new File("src/main/res/values/strings.xml").getAbsoluteFile().toURI().toURL(), Charsets.UTF_8); Pattern pattern = Pattern.compile("<string name=\"([^\"]+)\">([^<]+)</string>"); Matcher matcher = pattern.matcher(content); Map<String, String> values = Maps.newHashMap(); while (matcher.find()) { values.put(matcher.group(1), matcher.group(2)); } for (Field field : R.string.class.getDeclaredFields()) { int value = (int) field.get(R.string.class); given(context.getString(value)).willReturn(values.get(field.getName())); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.curator.x.rpc.CuratorProjectionServer.java
private static void printHelp() throws IOException { URL helpUrl = Resources.getResource("curator/help.txt"); System.out.println(Resources.toString(helpUrl, Charset.defaultCharset())); System.out.println();//from ww w .ja v a2 s . co m System.out.println("======= Curator Thrift IDL ======="); System.out.println(); URL idlUrl = Resources.getResource("curator.thrift"); System.out.println(Resources.toString(idlUrl, Charset.defaultCharset())); }
From source file:io.viewserver.server.steps.ViewServerSteps.java
@Given("^a report defined by \"([^\"]*)\"$") public void a_report_defined_by(String reportDefinitionFile) throws Throwable { JacksonSerialiser serialiser = new JacksonSerialiser(); String json = Resources.toString(Resources.getResource(reportDefinitionFile), Charsets.UTF_8); ReportDefinition reportDefinition = serialiser.deserialise(json, ReportDefinition.class); viewServerContext.master.getReportRegistry().register(reportDefinition); }
From source file:com.streamsets.pipeline.stage.processor.statsaggregation.RulesEvaluator.java
void raiseAlert(MetricRegistry metrics, RuleDefinition ruleDefinition, Object value) { Gauge<Object> gauge = MetricsConfigurator.getGauge(metrics, AlertsUtil.getAlertGaugeName(ruleDefinition.getId())); if (gauge == null) { AlertManagerHelper.createAlertResponseGauge(pipelineName, revision, metrics, value, ruleDefinition); } else {/*from w w w. j av a 2s.co m*/ AlertManagerHelper.updateAlertGauge(gauge, value, ruleDefinition); } if (ruleDefinition.isSendEmail()) { try { URL url = Resources.getResource(EmailConstants.METRIC_EMAIL_TEMPLATE); String emailBody = Resources.toString(url, Charsets.UTF_8); java.text.DateFormat dateTimeFormat = new SimpleDateFormat(EmailConstants.DATE_MASK, Locale.ENGLISH); emailBody = emailBody.replace(EmailConstants.ALERT_VALUE_KEY, String.valueOf(value)) .replace(EmailConstants.TIME_KEY, dateTimeFormat.format(new Date(System.currentTimeMillis()))) .replace(EmailConstants.PIPELINE_NAME_KEY, pipelineName) .replace(EmailConstants.CONDITION_KEY, ruleDefinition.getCondition()) .replace(EmailConstants.URL_KEY, pipelineUrl); if (ruleDefinition instanceof DataRuleDefinition) { emailBody = emailBody.replace(EmailConstants.ALERT_NAME_KEY, ((DataRuleDefinition) ruleDefinition).getLabel()); } else { emailBody = emailBody.replace(EmailConstants.ALERT_NAME_KEY, ruleDefinition.getAlertText()); } ContextExtensions ext = (ContextExtensions) context; ext.notify(emails, EmailConstants.STREAMSETS_DATA_COLLECTOR_ALERT + ruleDefinition.getAlertText(), emailBody); } catch (IOException | StageException e) { LOG.error("Error sending alert email, reason: {}", e.toString(), e); //Log error and move on. This should not stop the pipeline. } } }
From source file:com.facebook.buck.features.lua.AbstractNativeExecutableStarter.java
private String getNativeStarterCxxSourceTemplate() { try {// ww w . ja v a 2 s . c om return Resources.toString( Resources.getResource(AbstractNativeExecutableStarter.class, NATIVE_STARTER_CXX_SOURCE), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.spotify.cassandra.extra.EmbeddedCassandra.java
/** * Starts the embedded cassandra instance. * * @throws EmbeddedCassandraException if cassandra can't start up *//*from ww w . j a v a2 s.c om*/ public void start() throws IOException { if (running.compareAndSet(false, true)) { try { LOG.info("Creating Embedded Cassandra config file"); String baseFile = Resources.toString(CONFIG_TEMPLATE, Charset.defaultCharset()); String newFile = baseFile.replace("$DIR$", dataDir.toFile().getPath()); newFile = newFile.replace("$PORT$", Integer.toString(thriftPort)); newFile = newFile.replace("$STORAGE_PORT$", Integer.toString(storagePort)); newFile = newFile.replace("$NATIVE_TRANSPORT_PORT$", Integer.toString(nativeTransportPort)); Path configFile = dataDir.resolve("cassandra.yaml"); Files.write(configFile, ImmutableSet.of(newFile), StandardCharsets.UTF_8); LOG.info("Cassandra config file: " + configFile); System.setProperty("cassandra.config", "file:" + configFile.toString()); System.setProperty("cassandra-foreground", "true"); LOG.info("Starting Embedded Cassandra"); Future<Void> startupFuture = executorService.submit(new Callable<Void>() { @Override public Void call() throws Exception { cassandra.activate(); LOG.info("Embedded Cassandra started"); return null; } }); startupFuture.get(); } catch (InterruptedException | ExecutionException | IOException e) { throw new EmbeddedCassandraException("Can't start up cassandra", e); } } }
From source file:com.axemblr.provisionr.amazon.activities.SetupAdminAccess.java
private void uploadSudoersFile(SSHClient client) throws IOException { final String content = Resources.toString( Resources.getResource(getClass(), "/com/axemblr/provisionr/amazon/puppet/sudoers"), Charsets.UTF_8); Ssh.createFile(client, content, 0600, "/tmp/sudoers"); }