List of usage examples for com.google.common.io Resources getResource
public static URL getResource(Class<?> contextClass, String resourceName)
From source file:li.klass.fhem.fhem.DummyDataConnection.java
private RequestResult<String> xmllist() { try {//from w ww . j ava 2 s. com LOG.info("xmllist() - loading xmllist"); final DummyServerSpec dummyServerSpec = (DummyServerSpec) serverSpec; URL url = Resources.getResource(DummyDataConnection.class, dummyServerSpec.fileName); String content = Resources.toString(url, Charsets.UTF_8); content = content.replaceAll(" ", ""); return new RequestResult<>(content); } catch (IOException e) { LOG.error("xmllist() - cannot read file", e); throw new RuntimeException(e); } }
From source file:org.sonar.server.component.ws.ComponentsWs.java
private void defineSuggestionsAction(NewController controller) { NewAction action = controller.createAction("suggestions") .setDescription("Internal WS for the top-right search engine").setSince("4.2").setInternal(true) .setHandler(RailsHandler.INSTANCE) .setResponseExample(Resources.getResource(this.getClass(), "components-example-suggestions.json")); action.createParam("s").setRequired(true).setDescription("Substring of project key (minimum 2 characters)") .setExampleValue("sonar"); RailsHandler.addJsonOnlyFormatParam(action); }
From source file:app.MyLaMoradaStartApplication.java
private static String readLines(final String resourceName) { try {/*from w w w . ja v a 2 s . c o m*/ List<String> readLines = Resources.readLines( Resources.getResource(MyLaMoradaStartApplication.class, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (IOException e) { return "La Morada Petit Hotel"; } }
From source file:org.sonar.server.test.ws.CoveredFilesAction.java
@Override public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("covered_files").setDescription( "Get the list of source files covered by a test. Require Browse permission on test file's project") .setSince("4.4") .setResponseExample(Resources.getResource(getClass(), "tests-example-covered-files.json")) .setDeprecatedSince("5.6").setHandler(this).addPagingParams(100); action.createParam(TEST_ID).setRequired(true).setDescription("Test ID") .setExampleValue(Uuids.UUID_EXAMPLE_01); }
From source file:org.apache.isis.schema.utils.InteractionDtoUtils.java
public static InteractionDto fromXml(final Class<?> contextClass, final String resourceName, final Charset charset) throws IOException { final URL url = Resources.getResource(contextClass, resourceName); final String s = Resources.toString(url, charset); return fromXml(new StringReader(s)); }
From source file:com.nesscomputing.config.util.LocalHttpService.java
private static Connector getSSLHttpConnector() { final URL keystoreUrl = Resources.getResource(LocalHttpService.class, "/test-server-keystore.jks"); final SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath(keystoreUrl.toString()); contextFactory.setKeyStorePassword("changeit"); contextFactory.setKeyManagerPassword("changeit"); final SslSelectChannelConnector scc = new SslSelectChannelConnector(contextFactory); scc.setPort(0);/*from w w w.jav a2 s .c o m*/ scc.setHost("localhost"); return scc; }
From source file:com.facebook.buck.features.lua.AbstractLuaScriptStarter.java
private String getPureStarterTemplate() { try {// w w w. ja v a 2 s. c o m return Resources.toString(Resources.getResource(AbstractLuaScriptStarter.class, STARTER), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.mahout.cf.taste.example.grouplens.BooleanDataAndDateDataModel.java
public static File readResourceToTempFile(String resourceName) throws IOException { InputSupplier<? extends InputStream> inSupplier; try {//from w w w .j a v a2 s .c om URL resourceURL = Resources.getResource(GroupLensRecommender.class, resourceName); inSupplier = Resources.newInputStreamSupplier(resourceURL); } catch (IllegalArgumentException iae) { File resourceFile = new File(resourceName); inSupplier = Files.newInputStreamSupplier(resourceFile); } File tempFile = File.createTempFile("taste", null); tempFile.deleteOnExit(); Files.copy(inSupplier, tempFile); return tempFile; }
From source file:com.nesscomputing.httpclient.testsupport.LocalHttpService.java
private static Connector getSSLHttpConnector() { final URL keystoreUrl = Resources.getResource(LocalHttpService.class, "/ssl-server-keystore.jks"); final SslContextFactory contextFactory = new SslContextFactory(); contextFactory.setKeyStorePath(keystoreUrl.toString()); contextFactory.setKeyStorePassword("changeit"); contextFactory.setKeyManagerPassword("changeit"); final SslSelectChannelConnector scc = new SslSelectChannelConnector(contextFactory); scc.setPort(0);//from w w w . j a v a 2s .c o m scc.setHost("localhost"); return scc; }
From source file:org.isisaddons.module.docx.fixture.dom.templates.CustomerConfirmation.java
@PostConstruct public void init() throws IOException, LoadTemplateException { final byte[] bytes = Resources .toByteArray(Resources.getResource(this.getClass(), "CustomerConfirmation.docx")); wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes)); }