当前位置: 首页>>代码示例>>Java>>正文


Java Resources.toString方法代码示例

本文整理汇总了Java中com.google.common.io.Resources.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.toString方法的具体用法?Java Resources.toString怎么用?Java Resources.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.Resources的用法示例。


在下文中一共展示了Resources.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileAsString

import com.google.common.io.Resources; //导入方法依赖的package包/类
private String getFileAsString( final String resourcePath )
{
    String content = Constants.EMPTY;
    try
    {
        URL fileUrl = getClass().getClassLoader().getResource( resourcePath );
        if( fileUrl != null )
        {
            content = Resources.toString( fileUrl, Charsets.UTF_8 );
        }
    }
    catch( Exception e )
    {
        throw new RuntimeException( e );
    }
    return content;
}
 
开发者ID:hemano,项目名称:cucumber-framework-java,代码行数:18,代码来源:JavaScriptHelper.java

示例2: assertGenerated

import com.google.common.io.Resources; //导入方法依赖的package包/类
private static void assertGenerated(Class<?> clazz, String name, Consumer<ThriftIdlGeneratorConfig.Builder> configConsumer)
        throws IOException
{
    String expected = Resources.toString(getResource(format("expected/%s.txt", name)), UTF_8);

    ThriftIdlGeneratorConfig.Builder config = ThriftIdlGeneratorConfig.builder()
            .includes(ImmutableMap.of())
            .namespaces(ImmutableMap.of())
            .recursive(true);
    configConsumer.accept(config);

    ThriftIdlGenerator generator = new ThriftIdlGenerator(config.build());
    String idl = generator.generate(ImmutableList.of(clazz.getName()));

    assertEquals(idl, expected);
}
 
开发者ID:airlift,项目名称:drift,代码行数:17,代码来源:TestThriftIdlGenerator.java

示例3: testQueryBalance

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
public void testQueryBalance() throws Exception {

    String data = Resources.toString(getResource("json/coincheck_balance.json"), UTF_8);
    doReturn(data).when(target).executePrivate(GET, "https://coincheck.com/api/accounts/balance", null, null);

    // Found
    CoincheckBalance balance = target.queryBalance(Key.builder().build()).get();
    assertEquals(balance.getJpy(), new BigDecimal("1234.0"));
    assertEquals(balance.getBtc(), new BigDecimal("0.1"));

    // Cached
    doReturn(null).when(target).executePrivate(any(), any(), any(), any());
    CoincheckBalance cached = target.queryBalance(Key.builder().build()).get();
    assertSame(cached, balance);

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:18,代码来源:CoincheckContextTest.java

示例4: loadStringResource

import com.google.common.io.Resources; //导入方法依赖的package包/类
@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 ), Charset.forName ( "UTF-8" ) ); //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:StaticSymbolLoader.java

示例5: executeUpdateQueryFromResource

import com.google.common.io.Resources; //导入方法依赖的package包/类
public static void executeUpdateQueryFromResource(Connection connection, String resourceName) {
    URL resource = JDBCUtil.class.getResource(resourceName);
    try {
        String query = Resources.toString(resource, Charsets.UTF_8);
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate(query);
        }
        connection.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:13,代码来源:JDBCUtil.java

示例6: getFile

import com.google.common.io.Resources; //导入方法依赖的package包/类
public static String getFile(String resource) throws IOException{
  final URL url = Resources.getResource(resource);
  if (url == null) {
    throw new IOException(String.format("Unable to find path %s.", resource));
  }
  return Resources.toString(url, Charsets.UTF_8);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:8,代码来源:BaseTestQuery.java

示例7: testListTrades

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
public void testListTrades() throws Exception {

    Key key = Key.builder().instrument("TEST").build();
    String data = Resources.toString(getResource("json/poloniex_trade.json"), UTF_8);
    doReturn(data).when(target).request(GET, URL_TRADE + key.getInstrument(), null, null);

    // Found
    List<Trade> values = target.listTrades(key, null);
    assertEquals(values.size(), 2);
    assertEquals(values.get(0).getTimestamp(), Instant.ofEpochMilli(1505230796000L));
    assertEquals(values.get(0).getPrice(), new BigDecimal("0.07140271"));
    assertEquals(values.get(0).getSize(), new BigDecimal("0.20000000"));
    assertEquals(values.get(1).getTimestamp(), Instant.ofEpochMilli(1505230180000L));
    assertEquals(values.get(1).getPrice(), new BigDecimal("0.07124940"));
    assertEquals(values.get(1).getSize(), new BigDecimal("0.10772398"));

    // Cached
    doReturn(null).when(target).request(any(), any(), any(), any());
    List<Trade> cached = target.listTrades(key, null);
    assertEquals(cached, values);

    // Filtered
    List<Trade> filtered = target.listTrades(key, Instant.ofEpochMilli(1505230700000L));
    assertEquals(filtered.size(), 1);
    assertEquals(filtered.get(0), values.get(0));

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:29,代码来源:PoloniexContextTest.java

示例8: transformMarcToMods

import com.google.common.io.Resources; //导入方法依赖的package包/类
private PropBagEx transformMarcToMods(PropBagEx xml)
{
	try
	{
		String xslt = Resources.toString(getClass().getResource("MARC21slim2MODS3-3.xsl"), Charsets.UTF_8);
		String transXml = xsltService.transformFromXsltString(xslt, xml);
		return new PropBagEx(transXml);
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:14,代码来源:SrwServiceImpl.java

示例9: getScriptResource

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * Get the content of the name resource
 * 
 * @param resource resource filename
 * @return resource file content
 */
public static String getScriptResource(String resource) {
    URL url = Resources.getResource(resource);
    try {
        return Resources.toString(url, Charsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to load JavaScript resource '" + resource + "'", e);
    }
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:15,代码来源:JsUtility.java

示例10: createMininetTopoFromFile

import com.google.common.io.Resources; //导入方法依赖的package包/类
public static String createMininetTopoFromFile(URL url) throws IOException {
    String doc = Resources.toString(url, Charsets.UTF_8);
    doc = doc.replaceAll("\"dpid\": \"SW", "\"dpid\": \""); // remove any SW characters
    doc = doc.replaceAll("([0-9A-Fa-f]{2}):", "$1");         // remove ':' in id
    TopologyHelp.CreateMininetTopology(doc);
    return doc;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:8,代码来源:TestUtils.java

示例11: installOneSwitchPushFlow

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
public void installOneSwitchPushFlow() throws IOException, InterruptedException {
    String value = Resources.toString(getClass().getResource("/install_one_switch_push_flow.json"), Charsets.UTF_8);
    InstallOneSwitchFlow data = (InstallOneSwitchFlow) prepareData(value);
    OFMeterMod meterCommand = scheme.installMeter(data.getBandwidth(), 1024, data.getMeterId());
    OFFlowAdd flowCommand = scheme.oneSwitchPushFlowMod(data.getInputPort(), data.getOutputPort(),
            data.getOutputVlanId(), data.getMeterId(), 123L);
    runTest(value, flowCommand, meterCommand, null, null);
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:10,代码来源:ReplaceInstallFlowTest.java

示例12: installEgressReplaceFlow

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
public void installEgressReplaceFlow() throws IOException, InterruptedException {
    String value = Resources.toString(getClass().getResource("/install_egress_replace_flow.json"), Charsets.UTF_8);
    InstallEgressFlow data = (InstallEgressFlow) prepareData(value);
    OFFlowAdd flowCommand = scheme.egressReplaceFlowMod(data.getInputPort(), data.getOutputPort(),
            data.getTransitVlanId(), data.getOutputVlanId(), 123L);
    runTest(value, flowCommand, null, null, null);
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:9,代码来源:ReplaceInstallFlowTest.java

示例13: getFile

import com.google.common.io.Resources; //导入方法依赖的package包/类
private static String getFile(String resource) throws IOException {
  final URL url = Resources.getResource(resource);
  if (url == null) {
    throw new IOException(String.format("Unable to find path %s.", resource));
  }
  return Resources.toString(url, Charsets.UTF_8);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:8,代码来源:TestResourceLeak.java

示例14: testBasicMatch

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * testBasicMatch will verify that the test Topology using Guava Graphs and
 * the Mock object will agree.
 */
@Test
public void testBasicMatch() {
	URL url = Resources.getResource("topologies/topo.fullmesh.2.yml");
	String doc = "";
	try {
		doc = Resources.toString(url, Charsets.UTF_8);
		ITopology t1 = new Topology(doc);
		IController ctrl = new MockController(t1);
		ITopology t2 = ctrl.getTopology();
		assertTrue(t1.equivalent(t2));
	} catch (IOException e) {
		fail("Unexpected Exception:" + e.getMessage());
	}
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:19,代码来源:BasicTopoTests.java

示例15: readFromResources

import com.google.common.io.Resources; //导入方法依赖的package包/类
private String readFromResources(String filename) throws IOException {
  return Resources.toString(
      Resources.getResource("spec/search/" + filename), Charset.defaultCharset());
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:5,代码来源:SpecExamplesSerializationTest.java


注:本文中的com.google.common.io.Resources.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。