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:com.test.http.utils.ViewUtils.java

public static String render(String name) throws IOException {
    return Resources.toString(Resources.getResource(PREFIX + name + SUFFIX), Charsets.UTF_8);
}

From source file:org.apache.mahout.Version.java

public static String versionFromResource() throws IOException {
    return Resources.toString(Resources.getResource("version"), Charsets.UTF_8);
}

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

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

    graphics.setFont(new Font("OpenSans", Font.PLAIN, 34));
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    graphics.drawString(price + " USD", 86, 45);
    graphics.dispose();//from w w  w  . j a va 2s.co m

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

    return baos.toByteArray();
}

From source file:com.epam.reportportal.utils.SslUtils.java

/**
 * Load keystore/*from  w ww .java 2  s  .c  om*/
 *
 * @param keyStore keystore resource
 * @param password keystore password
 * @return JKD keystore representation
 */
public static KeyStore loadKeyStore(String keyStore, String password) {
    InputStream is = null;
    try {
        is = Resources.asByteSource(Resources.getResource(keyStore)).openStream();
        KeyStore trustStore = KeyStore.getInstance("JKS");
        trustStore.load(is, password.toCharArray());
        return trustStore;
    } catch (Exception e) {
        throw new RuntimeException("Unable to load trust store", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.mapr.workGroup.Constants.java

public static void loadResource(String resourceName) {
    try {/*from w w  w.  j  a v a2 s. co  m*/
        props.load(Resources.getResource(resourceName).openStream());
    } catch (IOException e) {
        throw new RuntimeException("Cannot load work group properties");
    }
}

From source file:com.zenika.doclipser.api.DockerClientFactory.java

private static String getDockerClientClassName() {
    final URL url = Resources.getResource(Constants.PROPERTY_FILE_NAME);
    final ByteSource byteSource = Resources.asByteSource(url);
    final Properties properties = new Properties();
    InputStream inputStream = null;
    try {/*w w w.ja va 2  s.com*/
        inputStream = byteSource.openBufferedStream();
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (final IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
    return properties.getProperty(Constants.PROPERTY_DOCKER_CLIENT_LIB);
}

From source file:com.github.steveash.jg2p.util.ReadWrite.java

public static <T> T readFromClasspath(Class<T> clazz, String resourceName)
        throws IOException, ClassNotFoundException {
    ByteSource bs = Resources.asByteSource(Resources.getResource(resourceName));
    return (T) readFromSource(bs);
}

From source file:com.streamsets.pipeline.kafka.api.KafkaFactoryUtil.java

public static String getFactoryClass(String factoryDefinitionFile, String factoryClassKey) {
    Properties def = new Properties();
    try {/* ww w. j  av  a2s . c  o m*/
        def.load(Resources.getResource(factoryDefinitionFile).openStream());
    } catch (Exception e) {
        throw new RuntimeException(
                Utils.format("Error creating an instance of SdcKafkaConsumerFactory : {}", e.toString()), e);
    }
    return def.getProperty(factoryClassKey);
}

From source file:org.praat.PraatFile.java

public static PraatObject read(String resource, Charset charset) throws Exception {
    // get path from resource
    String path;//from  w w w  .j a  v a 2s. c  o  m
    try {
        path = Resources.getResource(resource).getPath();
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Resource not found: " + resource);
    }

    // inspect file reading first line
    File file = new File(path);

    return readFromFile(file, charset);
}

From source file:com.shaie.utils.Utils.java

/** Returns a {@link File} from a resource. */
public static File getFileResource(String resourceName) {
    try {//  w w w  .  ja  v  a2 s . c  om
        return new File(Resources.getResource(resourceName).toURI());
        // return new File(Utils.class.getClassLoader().getResource(resourceName).toURI());
    } catch (final URISyntaxException e) {
        throw new RuntimeException(e);
    }
}