本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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$
}
示例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);
}
}
示例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);
}
示例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));
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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());
}