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