本文整理汇总了Java中com.google.common.io.Resources.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.getResource方法的具体用法?Java Resources.getResource怎么用?Java Resources.getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Resources
的用法示例。
在下文中一共展示了Resources.getResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readMapFile
import com.google.common.io.Resources; //导入方法依赖的package包/类
void readMapFile(String rulesFile) throws IOException
{
File file = new File(rulesFile);
URL rulesResource;
if (file.exists())
{
rulesResource = file.toURI().toURL();
}
else
{
rulesResource = Resources.getResource(rulesFile);
}
processATFile(Resources.asCharSource(rulesResource, Charsets.UTF_8));
FMLRelaunchLog.fine("Loaded %d rules from AccessTransformer config file %s", modifiers.size(), rulesFile);
}
示例2: 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);
}
}
示例3: 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);
}
示例4: getSslHandler
import com.google.common.io.Resources; //导入方法依赖的package包/类
public SslHandler getSslHandler() {
try {
URL ksUrl = Resources.getResource(keyStoreFile);
File ksFile = new File(ksUrl.toURI());
URL tsUrl = Resources.getResource(keyStoreFile);
File tsFile = new File(tsUrl.toURI());
TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore trustStore = KeyStore.getInstance(keyStoreType);
trustStore.load(new FileInputStream(tsFile), keyStorePassword.toCharArray());
tmFactory.init(trustStore);
KeyStore ks = KeyStore.getInstance(keyStoreType);
ks.load(new FileInputStream(ksFile), keyStorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, keyPassword.toCharArray());
KeyManager[] km = kmf.getKeyManagers();
TrustManager x509wrapped = getX509TrustManager(tmFactory);
TrustManager[] tm = {x509wrapped};
SSLContext sslContext = SSLContext.getInstance(TLS);
sslContext.init(km, tm, null);
SSLEngine sslEngine = sslContext.createSSLEngine();
sslEngine.setUseClientMode(false);
sslEngine.setNeedClientAuth(false);
sslEngine.setWantClientAuth(true);
sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
sslEngine.setEnableSessionCreation(true);
return new SslHandler(sslEngine);
} catch (Exception e) {
log.error("Unable to set up SSL context. Reason: " + e.getMessage(), e);
throw new RuntimeException("Failed to get SSL handler", e);
}
}
示例5: 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());
}
}
示例6: validateArclibXmlWithValidatorInvalidTag
import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
* Tests that the {@link MissingNode} exception is thrown when the ARCLib XML contains an invalid tag
*/
@Test
public void validateArclibXmlWithValidatorInvalidTag() {
URL arclibXml = Resources.getResource(INVALID_ARCLIB_XML_INVALID_TAG);
assertThrown(() -> validator.validateArclibXml(new ByteArrayInputStream(Resources.toByteArray(arclibXml)))).isInstanceOf
(SAXException.class);
}
示例7: getResource
import com.google.common.io.Resources; //导入方法依赖的package包/类
private static URL getResource(String fileName) throws IOException {
try {
return Resources.getResource(FileUtils.class, fileName);
} catch(IllegalArgumentException e) {
throw new FileNotFoundException(String.format("Unable to find file on path %s", fileName));
}
}
示例8: getDefaultDistributions
import com.google.common.io.Resources; //导入方法依赖的package包/类
public static synchronized Distributions getDefaultDistributions()
{
if (DEFAULT_DISTRIBUTIONS == null) {
try {
URL resource = Resources.getResource("dists.dss");
checkState(resource != null, "Distribution file 'dists.dss' not found");
DEFAULT_DISTRIBUTIONS = new Distributions(loadDistribution(Resources.asCharSource(resource, Charsets.UTF_8)));
}
catch (IOException e) {
throw Throwables.propagate(e);
}
}
return DEFAULT_DISTRIBUTIONS;
}
示例9: getFileContentsFromClassPath
import com.google.common.io.Resources; //导入方法依赖的package包/类
public static String getFileContentsFromClassPath(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, UTF_8);
}
示例10: loadResourceSpecification
import com.google.common.io.Resources; //导入方法依赖的package包/类
ResourceSpecification loadResourceSpecification() {
try {
URL url = Resources.getResource(getClass(), "CloudFormationResourceSpecification.json");
CharSource cs = Resources.asCharSource(url, StandardCharsets.UTF_8);
getLogger().info("Loading CFN resource specification from {}", cs);
ResourceSpecification spec = loadJson(cs);
getLogger().info("CFN resource specification loaded, version = {}", spec.getResourceSpecificationVersion());
return spec;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例11: open
import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public FSDataInputStream open(Path arg0, int arg1) throws IOException {
String file = getFileName(arg0);
URL url = Resources.getResource(file);
if(url == null){
throw new IOException(String.format("Unable to find path %s.", arg0.getName()));
}
ResourceInputStream ris = new ResourceInputStream(Resources.toByteArray(url));
return new FSDataInputStream(ris);
}
示例12: testScan
import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
public void testScan() throws Exception {
AbstractRedisDialect dialect = RedisTestHelper.getDialect( getProvider() );
assumeTrue( dialect.isClusterMode() );
// pre-computed key file.
URL resource = Resources.getResource( "redis-cluster-slothashes.txt" );
List<String> lines = Resources.readLines( resource, StandardCharsets.ISO_8859_1 );
OgmSession session = openSession();
session.getTransaction().begin();
// given
int availableKeys = 0;
for ( String line : lines ) {
if ( line.startsWith( "#" ) || line.trim().isEmpty() ) {
continue;
}
String key = line.substring( 0, line.indexOf( ' ' ) ).trim();
Band record = new Band( key, key );
session.persist( record );
availableKeys++;
}
session.getTransaction().commit();
final AtomicInteger counter = new AtomicInteger();
dialect.forEachTuple( new ModelConsumer() {
@Override
public void consume(TuplesSupplier supplier) {
try ( ClosableIterator<Tuple> closableIterator = supplier.get( null ) ) {
while ( closableIterator.hasNext() ) {
counter.incrementAndGet();
}
}
}
}, null, new DefaultEntityKeyMetadata( "Band", new String[] {"id"} ) );
assertEquals( availableKeys, counter.get() );
}
示例13: getURL
import com.google.common.io.Resources; //导入方法依赖的package包/类
private static URL getURL(final Class<?> testClass, final String defaultAppConfigFileName) {
return Resources.getResource(testClass, defaultAppConfigFileName);
}
示例14: loadBuffersFromResource
import com.google.common.io.Resources; //导入方法依赖的package包/类
public static List<IoBuffer> loadBuffersFromResource ( final Class<?> clazz, final String resourceName ) throws IOException
{
logger.debug ( "Loading buffer - {}", resourceName );
final URL url = Resources.getResource ( clazz, resourceName );
return Resources.readLines ( url, Charset.forName ( "UTF-8" ), new LineProcessor<List<IoBuffer>> () {
private final List<IoBuffer> result = new LinkedList<> ();
private IoBuffer buffer = null;
protected void pushBuffer ()
{
if ( this.buffer == null )
{
return;
}
this.buffer.flip ();
this.result.add ( this.buffer );
this.buffer = null;
}
@Override
public boolean processLine ( String line ) throws IOException
{
line = line.replaceAll ( "#.*", "" ); // clear comments
if ( line.isEmpty () )
{
pushBuffer ();
return true;
}
final String[] toks = line.split ( "\\s+" );
if ( toks.length <= 0 )
{
pushBuffer ();
return true;
}
if ( this.buffer == null )
{
// start a new buffer
this.buffer = IoBuffer.allocate ( 0 );
this.buffer.setAutoExpand ( true );
}
for ( final String tok : toks )
{
this.buffer.put ( Byte.parseByte ( tok, 16 ) );
}
return true;
}
@Override
public List<IoBuffer> getResult ()
{
pushBuffer (); // last chance to add something
return this.result;
}
} );
}
示例15: readMapFile
import com.google.common.io.Resources; //导入方法依赖的package包/类
private void readMapFile(String rulesFile) throws IOException
{
File file = new File(rulesFile);
URL rulesResource;
if (file.exists())
{
rulesResource = file.toURI().toURL();
}
else
{
rulesResource = Resources.getResource(rulesFile);
}
Resources.readLines(rulesResource, Charsets.UTF_8, new LineProcessor<Void>()
{
@Override
public Void getResult()
{
return null;
}
@Override
public boolean processLine(String input) throws IOException
{
String line = Iterables.getFirst(Splitter.on('#').limit(2).split(input), "").trim();
if (line.length()==0)
{
return true;
}
List<String> parts = Lists.newArrayList(Splitter.on(" ").trimResults().split(line));
if (parts.size()!=2)
{
throw new RuntimeException("Invalid config file line "+ input);
}
List<String> markerInterfaces = Lists.newArrayList(Splitter.on(",").trimResults().split(parts.get(1)));
for (String marker : markerInterfaces)
{
markers.put(parts.get(0), marker);
}
return true;
}
});
}