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.apache.wave.box.server.rpc.InitialsAvatarsServlet.java

@Inject
public InitialsAvatarsServlet() throws IOException {
    DEFAULT = ImageIO.read(Resources.getResource("org/apache/wave/box/server/rpc/InitialsAvatarDefault.jpg"));
}

From source file:org.glowroot.container.impl.DelegatingJavaagent.java

static File createDelegatingJavaagentJarFile(File dir) throws Exception {
    File jarFile = File.createTempFile("glowroot-", ".jar", dir);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().put(new Attributes.Name("Premain-Class"), DelegatingJavaagent.class.getName());
    manifest.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true");
    manifest.getMainAttributes().put(new Attributes.Name("Can-Retransform-Classes"), "true");
    JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile), manifest);
    String resourceName = ClassNames.toInternalName(DelegatingJavaagent.class.getName()) + ".class";
    out.putNextEntry(new JarEntry(resourceName));
    Resources.asByteSource(Resources.getResource(resourceName)).copyTo(out);
    out.closeEntry();/*w w  w  . j a v  a 2s . c o  m*/
    out.close();
    return jarFile;
}

From source file:org.mayocat.shop.shipping.rest.resource.DestinationsResource.java

@GET
@Path("flat")
public Response getDestinationsFlat() {
    try {//from ww w  .jav  a  2s.c o  m
        return Response.ok(Resources.toString(
                Resources.getResource("org/mayocat/shop/shipping/destinations/earth_flat.json"),
                Charsets.UTF_8)).build();
    } catch (IOException e) {
        this.logger.error("Failed to get location file", e);
        return Response.serverError().build();
    }
}

From source file:com.viadeo.kasper.platform.Build.java

public static Info info(final ObjectMapper objectMapper) {
    try {//www  .j  a v  a2s  .  c om
        return objectMapper.readValue(Resources.getResource("buildInfo.json"), Info.class);
    } catch (Throwable e) {
        LOGGER.warn("Failed to load platform meta information", e);
    }

    return unknownInfo;
}

From source file:org.glowroot.agent.it.harness.impl.DelegatingJavaagent.java

static File createDelegatingJavaagentJarFile(File dir) throws Exception {
    File jarFile = File.createTempFile("glowroot-", ".jar", dir);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().put(new Attributes.Name("Premain-Class"), DelegatingJavaagent.class.getName());
    manifest.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true");
    manifest.getMainAttributes().put(new Attributes.Name("Can-Retransform-Classes"), "true");
    String resourceName = ClassNames.toInternalName(DelegatingJavaagent.class.getName()) + ".class";
    JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile), manifest);
    try {//from   www  . ja v a 2 s. c om
        out.putNextEntry(new JarEntry(resourceName));
        Resources.asByteSource(Resources.getResource(resourceName)).copyTo(out);
        out.closeEntry();
    } finally {
        out.close();
    }
    return jarFile;
}

From source file:com.cognifide.qa.bb.module.PropertiesLoaderModule.java

private Properties getProperties() throws IOException {
    Properties properties = new Properties();
    for (String propertiesFileName : propertiesFileNames) {
        try (InputStream inputStream = Resources.getResource(propertiesFileName).openStream()) {
            properties.load(inputStream);
        }//from w  ww .  ja  v a 2 s.c  o m
    }
    return properties;
}

From source file:com.github.blacklocus.rdsecho.EchoSampleProps.java

@Override
public Boolean call() throws Exception {

    URL sampleProps = Resources.getResource(EchoConst.CONFIGURATION_PROPERTIES + ".sample");
    Path destination = Paths.get(EchoConst.CONFIGURATION_PROPERTIES);
    if (destination.toFile().exists()) {
        LOG.info("rdsecho.properties already exists at {}. Will not overwrite.", destination.toAbsolutePath());
        return false;
    }/*from www .  j a v  a 2  s  .c om*/
    try (InputStream samplePropsInputStream = sampleProps.openStream()) {
        Files.copy(samplePropsInputStream, destination);
    }

    LOG.info("Sample configuration written to {}. While some property values are optional, it is strongly "
            + "recommended that all be populated.", destination.toAbsolutePath());

    return false;
}

From source file:io.soabase.sql.attributes.SqlBundle.java

@Override
public void run(T configuration, Environment environment) throws Exception {
    SqlConfiguration sqlConfiguration = ComposedConfigurationAccessor.access(configuration, environment,
            SqlConfiguration.class);
    try {/*from  w  w w .jav a2 s  . c om*/
        try (InputStream stream = Resources.getResource(sqlConfiguration.getMybatisConfigUrl()).openStream()) {
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream);
            Configuration mybatisConfiguration = sqlSessionFactory.getConfiguration();
            mybatisConfiguration.addMapper(AttributeEntityMapper.class);
            final SqlSession session = sqlSessionFactory.openSession(true);

            SoaBundle.getFeatures(environment).putNamed(session, SqlSession.class, sqlConfiguration.getName());
            Managed managed = new Managed() {
                @Override
                public void start() throws Exception {

                }

                @Override
                public void stop() throws Exception {
                    session.close();
                }
            };
            environment.lifecycle().manage(managed);
        }
    } catch (Exception e) {
        // TODO logging
        log.error("Could not initialize MyBatis", e);
        throw new RuntimeException(e);
    }
}

From source file:com.quinsoft.zeidon.objectbrowser.ObjectBrowser.java

protected void startup() {
    // Create and set up the window.
    mainFrame = new JFrame();
    mainFrame.setTitle("Zeidon Object Browser");
    mainFrame.setName("Object Browser");
    mainFrame.getContentPane().add(new MainPanel(env));

    URL iconUrl = Resources.getResource("tzobrwad.png");
    ImageIcon image = new ImageIcon(iconUrl);
    mainFrame.setIconImage(image.getImage());

    BrowserEventHandler listener = new BrowserEventHandler();
    mainFrame.addWindowStateListener(listener);
    mainFrame.addWindowListener(listener);
    mainFrame.pack();//from  w  w  w  .  ja va 2  s .c o m

    env.restoreEnvironment();

    // Display the window.
    mainFrame.setVisible(true);

    // Use invokeLater otherwise toFront() won't always work.
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            mainFrame.toFront();
        }
    });

}

From source file:hrytsenko.gscripts.App.java

private static void executeEmbeddedScript(GroovyShell shell, String scriptName) {
    try {//w  w w.j  a v  a2 s .  c o m
        shell.evaluate(Resources.toString(Resources.getResource(scriptName), StandardCharsets.UTF_8));
    } catch (IOException exception) {
        throw new AppException(String.format("Cannot execute embedded script %s.", scriptName), exception);
    }
}