Example usage for com.google.common.io Resources toString

List of usage examples for com.google.common.io Resources toString

Introduction

In this page you can find the example usage for com.google.common.io Resources toString.

Prototype

public static String toString(URL url, Charset charset) throws IOException 

Source Link

Document

Reads all characters from a URL into a String , using the given character set.

Usage

From source file:org.apache.aurora.scheduler.events.WebhookModule.java

@VisibleForTesting
static String readWebhookFile() {
    try {/*w w w . j  a v a2s. c o m*/
        return WEBHOOK_CONFIG_FILE.hasAppliedValue()
                ? Files.toString(WEBHOOK_CONFIG_FILE.get(), StandardCharsets.UTF_8)
                : Resources.toString(Webhook.class.getClassLoader().getResource(WEBHOOK_CONFIG_PATH),
                        StandardCharsets.UTF_8);
    } catch (IOException e) {
        LOG.error("Error loading webhook configuration file.");
        throw new RuntimeException(e);
    }
}

From source file:io.hops.hopsworks.common.util.IoUtils.java

public static String readContentFromWeb(String url) throws IOException {
    URL fileUrl = new URL(url);
    return Resources.toString(fileUrl, Charsets.UTF_8);
}

From source file:org.apache.provisionr.amazon.activities.SetupAdminAccess.java

@Override
public Map<String, String> createAdditionalFiles(Pool pool, Machine machine) {
    try {//from  w w  w.j av  a 2  s  .c om
        return ImmutableMap.of("/tmp/sshd_config",
                Mustache.toString(getClass(), SSHD_CONFIG_TEMPLATE,
                        ImmutableMap.of("user", pool.getAdminAccess().getUsername())),
                "/tmp/sudoers",
                Resources.toString(Resources.getResource(getClass(), SUDOERS_TEMPLATE), Charsets.UTF_8));

    } catch (IOException e) {
        throw Throwables.propagate(e);
    }

}

From source file:com.eucalyptus.portal.awsusage.CassandraSessionManager.java

private static synchronized void initCluster(String contactPoint) {
    if (session != null) {
        session.close();//from   w w  w. j a v a  2  s.  co m
        session = null;
    }
    if (cluster != null) {
        cluster.close();
        cluster = null;
    }
    LOG.info("Trying to connect to the cluster " + contactPoint);
    List<String> contactPoints = Lists.newArrayList();
    for (String s : Splitter.on(",").omitEmptyStrings().split(contactPoint)) {
        contactPoints.add(s);
    }
    cluster = Cluster.builder().addContactPoints(contactPoints.toArray(new String[0])).build();
    session = cluster.connect();

    // create new keyspace/tables (should not do here)  TODO: move
    session.execute("CREATE KEYSPACE IF NOT EXISTS eucalyptus_billing "
            + "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}; ");

    session.execute("USE eucalyptus_billing;");

    try {
        final String cql = Resources.toString(Resources.getResource("2017-03-28-eucalyptus-billing-base.cql"),
                StandardCharsets.UTF_8);
        CqlUtil.splitCql(cql).forEach(session::execute);
    } catch (final IOException | ParseException e) {
        throw Exceptions.toUndeclared(e);
    }
}

From source file:com.squareup.rack.examples.dropwizard.ExampleService.java

private String readResource(String path) {
    try {/*  w ww . ja  v a2 s.  c o  m*/
        return Resources.toString(getResource(path), defaultCharset());
    } catch (IOException e) {
        throw propagate(e);
    }
}

From source file:org.opennms.newts.cassandra.AbstractCassandraTestCase.java

public CQLDataSet getDataSet() {
    try {/*from  w  w w .  ja  v a2  s. c om*/
        String schema = Resources.toString(getClass().getResource(getSchemaResource()), Charsets.UTF_8);
        schema = schema.replace(KEYSPACE_PLACEHOLDER, CASSANDRA_KEYSPACE);
        File schemaFile = File.createTempFile("schema-", ".cql", new File("target"));
        Files.write(schema, schemaFile, Charsets.UTF_8);

        return new FileCQLDataSet(schemaFile.getAbsolutePath(), false, true, CASSANDRA_KEYSPACE);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.jsfr.json.BenchmarkCollectObject.java

@Setup
public void setup() throws Exception {
    gsonSurfer = JsonSurfer.gson();/*from  ww  w  .  ja va  2  s . co  m*/
    jacksonSurfer = JsonSurfer.jackson();
    simpleSurfer = JsonSurfer.simple();
    TypedJsonPathListener collectOneListener = new TypedJsonPathListener() {

        private Blackhole blackhole = new Blackhole();

        @Override
        public void onTypedValue(Object value, ParsingContext context) throws Exception {
            blackhole.consume(value);
        }
    };
    surfingConfiguration = SurfingConfiguration.builder().bind("$.store.book[*]", Map.class, collectOneListener)
            .build();
    json = Resources.toString(Resources.getResource("sample.json"), StandardCharsets.UTF_8);
}

From source file:com.axemblr.provisionr.amazon.activities.RunOnDemandInstances.java

@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) throws IOException {
    final String businessKey = execution.getProcessBusinessKey();

    final String securityGroupName = SecurityGroups.formatNameFromBusinessKey(businessKey);
    final String keyPairName = KeyPairs.formatNameFromBusinessKey(businessKey);

    final String instanceType = pool.getHardware().getType();
    final String imageId = getImageIdFromProcessVariablesOrQueryImageTable(execution, pool.getProvider(),
            instanceType);/* w w  w  . ja va 2  s  .  c  o  m*/

    final String userData = Resources.toString(
            Resources.getResource(RunOnDemandInstances.class, "/com/axemblr/provisionr/amazon/userdata.sh"),
            Charsets.UTF_8);

    final RunInstancesRequest request = new RunInstancesRequest().withClientToken(businessKey)
            .withSecurityGroups(securityGroupName).withKeyName(keyPairName).withInstanceType(instanceType)
            .withImageId(imageId).withMinCount(pool.getMinSize()).withMaxCount(pool.getExpectedSize())
            .withUserData(Base64.encodeBytes(userData.getBytes(Charsets.UTF_8)));

    // TODO allow for more options (e.g. monitoring & termination protection etc.)

    LOG.info(">> Sending RunInstances request: {}", request);
    RunInstancesResult result = client.runInstances(request);
    LOG.info("<< Got RunInstances result: {}", result);

    // TODO tag instances: managed-by: Axemblr Provisionr, business-key: ID etc.

    execution.setVariable(ProcessVariables.RESERVATION_ID, result.getReservation().getReservationId());
    execution.setVariable(ProcessVariables.INSTANCE_IDS,
            collectInstanceIdsAsList(result.getReservation().getInstances()));
}

From source file:org.obm.provisioning.H2Initializer.java

private String getInitialDBScript() throws IOException {
    URL initialDbScriptUrl = Resources.getResource(INITIAL_DB_SCRIPT);
    return Resources.toString(initialDbScriptUrl, Charsets.UTF_8);
}

From source file:org.eclipse.che.util.GwtXmlGenerator.java

/**
 * Get the template for typescript//from w  w  w  . j a va 2 s.  c  om
 *
 * @return the String Template
 */
protected ST getTemplate() {
    URL url = Resources.getResource(GwtXmlGenerator.class, TEMPLATE_NAME);
    try {
        return new ST(Resources.toString(url, UTF_8), '$', '$');
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to read template", e);
    }

}