List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:org.opennms.newts.persistence.cassandra.AbstractCassandraTestCase.java
@Override public CQLDataSet getDataSet() { try {// w w w. ja v a 2 s . com String schema = Resources.toString(getClass().getResource(SCHEMA_RESOURCE), Charsets.UTF_8); schema = schema.replace(KEYSPACE_PLACEHOLDER, KEYSPACE_NAME); File schemaFile = File.createTempFile("schema-", ".cql", new File("target")); Files.write(schema, schemaFile, Charsets.UTF_8); return new FileCQLDataSet(schemaFile.getAbsolutePath(), false, true, KEYSPACE_NAME); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.eclipse.scada.vi.ui.draw2d.loader.XMISymbolLoader.java
@Override public String loadStringResource(final String url) throws Exception { final String target = resolveUri(url); logger.debug("Loading resource from: {}", target); //$NON-NLS-1$ return Resources.toString(new URL(target), StandardCharsets.UTF_8); }
From source file:co.jirm.core.util.ResourceUtils.java
private static String _getClasspathResourceAsString(Class<?> k, String path) throws IOException { return Resources.toString(Resources.getResource(k, path), Charsets.UTF_8); }
From source file:eu.numberfour.n4js.antlr.replacements.Replacements.java
/** * Applies a replacement, which is a string containing both the lookup (non-regex) and the replacement.These two * strings are separated via/*from w w w .j a v a 2s . co m*/ * * <pre> * _________________________________REPLACE_WITH_________________________________ * </pre> * * The replacement file has to be in the same folder as this class. */ public static String applyReplacement(String in, String replacementName) { try { URL url = ClassLoader.getSystemResource( Replacements.class.getPackage().getName().replace(".", "/") + "/" + replacementName); // normalize string to run on Windows and Mac/Unix String replacement = Resources.toString(url, Charsets.UTF_8).replace("\r\n", "\n"); String[] findReplace = replacement .split("\n_________________________________REPLACE_WITH_________________________________\n"); return replace(in, findReplace[0], findReplace[1]); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:li.klass.fhem.fhem.DummyDataConnection.java
private RequestResult<String> xmllist() { try {/*ww w. j a va2s. c o m*/ 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:com.atoito.please.core.api.OpsFile.java
private String loadDsl(URL url) { URL u = Preconditions.checkNotNull(url, "ops file cannot have null url"); String dsl = ""; String protocol = u.getProtocol(); if ("file".equals(protocol)) { File resource = fileFromUrl(u); if (resource.isDirectory()) { M.debug("supposed ops file %s is actually a directory...", u); return dsl; }//from www . jav a 2 s . c o m } try { dsl = Resources.toString(u, Charsets.UTF_8); } catch (IOException e) { Throwables.propagate(e); } return dsl; }
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:uk.co.blackpepper.support.okhttp.test.MockWebServerRule.java
protected final String getContent(String name) throws IOException { return Resources.toString(Resources.getResource(getClass(), name), Charsets.UTF_8); }
From source file:annis.gui.requesthandler.LoginServletRequestHandler.java
private void doGet(VaadinSession session, VaadinRequest request, VaadinResponse response) { response.setContentType("text/html"); OutputStream out = null;//from w ww.ja va 2 s. c o m try { out = response.getOutputStream(); String htmlSource = Resources.toString(LoginServletRequestHandler.class.getResource("login.html"), Charsets.UTF_8); htmlSource = htmlSource.replaceAll("%usercaption%", "Username") .replaceAll("%passwordcaption%", "Password").replaceAll("%title%", "ANNIS Login") .replaceAll("%logincaption%", "Login").replaceAll("%or%", "or") .replaceAll("%cancelcaption%", "Cancel"); try (OutputStreamWriter writer = new OutputStreamWriter(out, Charsets.UTF_8)) { CharStreams.copy(new StringReader(htmlSource), writer); out.flush(); } } catch (IOException ex) { log.error(null, ex); } catch (Exception ex) { log.error(null, ex); } finally { response.setStatus(200); if (out != null) { try { out.close(); } catch (IOException ex) { log.error("closing OutputStream filed", ex); } } } }
From source file:com.mgmtp.jfunk.data.generator.config.GeneratorModule.java
@Provides @Singleton/*from w w w. j av a 2 s . co m*/ @LoremIpsum String provideLoremIpsum() throws IOException { return Resources.toString(Resources.getResource("lorem_ipsum.txt"), Charsets.UTF_8); }