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


Java Resources.readLines方法代码示例

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


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

示例1: addingBundle

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public Boolean addingBundle(final Bundle bundle, final BundleEvent event) {
    URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
    LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}", bundle, resource, event);
    if (resource != null) {
        try {
            for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
                registerFactory(factoryClassName, bundle);
            }

            return Boolean.TRUE;
        } catch (final IOException e) {
            LOG.error("Error while reading {}", resource, e);
            throw new RuntimeException(e);
        }
    }

    return Boolean.FALSE;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:ModuleFactoryBundleTracker.java

示例2: get

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public WidgetData get() {
    try {
        WidgetData clzDescriptors
                = Resources.readLines(url, Charsets.ISO_8859_1,
                        new LineProcessorImpl());
        return clzDescriptors;
    } catch (IOException ex) {
        LOG.log(Level.INFO, null, ex);
        return new WidgetData(Collections.<LayoutElementType, Collection<UIClassDescriptor>>emptyMap(),
                Collections.<UIClassDescriptor>emptySet());
    }
}
 
开发者ID:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:14,代码来源:LayoutClassesParser.java

示例3: bundleAdded

import com.google.common.io.Resources; //导入方法依赖的package包/类
private void bundleAdded(final Bundle bundle) {
    URL resource = bundle.getEntry(serviceResourcePath);
    if (resource == null) {
        return;
    }

    LOG.debug("{}: Found {} resource in bundle {}", logName(), resource, bundle.getSymbolicName());

    try {
        for (String line : Resources.readLines(resource, StandardCharsets.UTF_8)) {
            int ci = line.indexOf('#');
            if (ci >= 0) {
                line = line.substring(0, ci);
            }

            line = line.trim();
            if (line.isEmpty()) {
                continue;
            }

            String serviceType = line;
            LOG.debug("{}: Retrieved service type {}", logName(), serviceType);
            expectedServiceTypes.add(serviceType);
        }
    } catch (final IOException e) {
        setFailure(String.format("%s: Error reading resource %s from bundle %s", logName(), resource,
                bundle.getSymbolicName()), e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:30,代码来源:SpecificReferenceListMetadata.java

示例4: 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() );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:45,代码来源:RedisDialectClusterForEachTest.java

示例5: 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;
        }
    } );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:67,代码来源:BufferLoader.java

示例6: getResourceAsString

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * Reads and joins together with LF char (\n) all the lines from given file. It's assumed that file is in UTF-8.
 */
public static String getResourceAsString(URL url) throws IOException {
    List<String> lines = Resources.readLines(url, Charsets.UTF_8);
    return Joiner.on('\n').join(lines);
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:8,代码来源:Utils.java

示例7: getResourceAsString

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * Reads and joins together with LF char (\n) all the lines from given file.
 * It's assumed that file is in UTF-8.
 */
public static String getResourceAsString(URL url) throws IOException {
    List<String> lines = Resources.readLines(url, Charsets.UTF_8);
    return Joiner.on('\n').join(lines);
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:9,代码来源:CryptoUtils.java

示例8: 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;
        }
    });
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:43,代码来源:MarkerTransformer.java

示例9: toLines

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * 读取文件的每一行,读取规则见本类注释.
 */
public static List<String> toLines(String resourceName) throws IOException {
	return Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:ResourceUtil.java

示例10: readLines

import com.google.common.io.Resources; //导入方法依赖的package包/类
private Set<String> readLines(final String fileName) throws IOException {
    return new HashSet<>(Resources.readLines(getClass().getResource(fileName), StandardCharsets.UTF_8));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:4,代码来源:CapabilityStrippingConfigSnapshotHolderTest.java


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