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