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

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

Introduction

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

Prototype

public static URL getResource(String resourceName) 

Source Link

Document

Returns a URL pointing to resourceName if the resource is found using the Thread#getContextClassLoader() context class loader .

Usage

From source file:org.whispersystems.bithub.util.Badge.java

public static byte[] createSmallFor(String price) throws IOException {
    byte[] badgeBackground = Resources.toByteArray(Resources.getResource("assets/badge-small.png"));
    BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(badgeBackground));
    Graphics2D graphics = bufferedImage.createGraphics();

    graphics.setFont(new Font("OpenSans", Font.PLAIN, 9));
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    graphics.drawString(price + " USD", 22, 14);
    graphics.dispose();//from w w w  . ja v a2  s .c  om

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", baos);

    return baos.toByteArray();
}

From source file:eu.redzoo.article.planetcassandra.reactive.service.PictureService.java

@Path("/{id}")
@GET/*from ww w  .  j av  a 2 s.  c  om*/
@Produces("image/png")
public byte[] getHotelThumbnail() throws IOException {
    return Resources.toByteArray(Resources.getResource("hotel.png"));
}

From source file:keywhiz.service.config.ResourcesHttpsConnectorFactory.java

private static String resolveResource(String resource) {
    return Resources.getResource(resource).getPath();
}

From source file:ezbake.common.io.ClasspathResources.java

public static URL getResource(String resource) {
    // no need to attempt to load
    if (Strings.isNullOrEmpty(resource)) {
        return null;
    }//from  w w w .  j  a  v  a2s. c  o  m

    // First we will do it from class loaders
    URL retVal = null;
    try {
        retVal = Resources.getResource(resource);
    } catch (IllegalArgumentException ignored) {
        // We are ignoring this so we can try to load from the runtime classes
    }

    retVal = ClasspathResources.class.getClass().getResource(resource);
    if (retVal == null) {
        /* Just in case the java.class and ClasspathResources are loaded from differrent class loader then
        java.lang.class */
        retVal = ClasspathResources.class.getResource(resource);
    }
    return retVal;
}

From source file:com.github.tomakehurst.wiremock.common.HttpsSettings.java

public HttpsSettings(int port) {
    this(port, Resources.getResource("keystore").toString());
}

From source file:org.apache.sentry.provider.file.PolicyFiles.java

public static void copyToDir(FileSystem fs, Path dest, String... resources)
        throws FileNotFoundException, IOException {
    for (String resource : resources) {
        InputStream in = Resources.getResource(resource).openStream();
        FSDataOutputStream out = fs.create(new Path(dest, resource));
        long bytes = ByteStreams.copy(in, out);
        in.close();/*  w  w w  . j ava2 s. c o m*/
        out.hflush();
        out.close();
        LOGGER.info("Copying " + resource + " to " + dest + ", bytes " + bytes);
    }
}

From source file:com.madvay.tools.android.perf.apat.Main.java

private static void printUsage() {
    try {/*from ww w.j  a  v  a  2  s. com*/
        List<String> lines = Resources.readLines(Resources.getResource("README.txt"), Charsets.UTF_8);
        boolean foundUsage = false, foundBeginHash = false;

        /*
         * We want to output the lines of usage in the README.md file:
                
        <other stuff>
        ## Usage
        ```
        <stuff to display>
        ```
        <other stuff>
                
         */
        lineLoop: for (String l : lines) {
            if (foundUsage) {
                if (foundBeginHash) {
                    if (l.equals("```")) {
                        // end!
                        break lineLoop;
                    }
                    outln(l);
                }
                if (l.equals("```")) {
                    foundBeginHash = true;
                }
            }
            if (l.equals("## Usage")) {
                foundUsage = true;
            }
        }
    } catch (IOException err) {
        err(err);
    }
}

From source file:com.streamsets.datacollector.kafka.standalone.KafkaDestinationSinglePartitionPipelineOperationsIT.java

private static String getPipelineJson() throws Exception {
    URI uri = Resources.getResource("kafka_destination_pipeline_operations.json").toURI();
    String pipelineJson = new String(Files.readAllBytes(Paths.get(uri)), StandardCharsets.UTF_8);
    pipelineJson = pipelineJson.replace("topicName", TOPIC);
    pipelineJson = pipelineJson.replaceAll("localhost:9092", KafkaTestUtil.getMetadataBrokerURI());
    pipelineJson = pipelineJson.replaceAll("localhost:2181", KafkaTestUtil.getZkServer().connectString());
    return pipelineJson;
}

From source file:org.apache.drill.plan.ParsePlan.java

public static Plan parseResource(String resourceName) throws ParseException {
    return ParsePlan.parse(Resources.newReaderSupplier(Resources.getResource(resourceName), Charsets.UTF_8));
}

From source file:org.trnltk.morphology.lexicon.DictionaryLoader.java

public static HashSet<Lexeme> loadDefaultNumeralMasterDictionary() {
    final CharSource charSource = Resources
            .asCharSource(Resources.getResource("master-numeral-dictionary.dict"), Charset.forName("utf-8"));
    return new DictionaryLoader().load(charSource);
}