當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。