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


Java Resources.asByteSource方法代码示例

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


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

示例1: resource

import com.google.common.io.Resources; //导入方法依赖的package包/类
public static InputStream resource(String path) throws IOException {
    try {
        URL url = Resources.getResource(path);
        ByteSource source = Resources.asByteSource(url);
        return source.openStream();
    } catch (IllegalArgumentException ex) {
        throw new MissingObject("template", path);
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:10,代码来源:Utils.java

示例2: speed

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
    public void speed() throws IOException {
        MynlpTokenizer tokenizer = MynlpSegments.crf();

        String line =

                "第六十八回  苦尤娘赚入大观园 ";

        tokenizer.token(line.toCharArray()).forEach(
                System.out::println
        );


        URL urlinclass = Resources.getResource("xiyouji.txt");
        ByteSource source = Resources.asByteSource(urlinclass);
        String text = source.asCharSource(Charsets.UTF_8).read();
        List<String> lines = Lists.newArrayList(text.split("\n"));

//        CommonAnalyzer ba = new CommonAnalyzer(new StringReader(text),tokenizer);

        long t1 = System.currentTimeMillis();
//        for (MyTerm myTerm : ba) {
//            //System.out.println(myTerm);
//        }

        System.out.println(lines.size());
        for (String s : lines) {
            tokenizer.token(s.toCharArray());
        }
        long t2 = System.currentTimeMillis();
        System.out.println(t2 - t1);
    }
 
开发者ID:mayabot,项目名称:mynlp,代码行数:33,代码来源:ViterbiTest.java

示例3: getLetsEncryptContext

import com.google.common.io.Resources; //导入方法依赖的package包/类
private static SSLContext getLetsEncryptContext() throws Exception {

        final URL url = Resources.getResource("DSTRootCAX3.crt");
        final ByteSource byteSource = Resources.asByteSource(url);

        try (final InputStream inputStream = byteSource.openBufferedStream()) {

            final Certificate certificate = CertificateFactory.getInstance("X.509")
                .generateCertificate(inputStream);

            final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());

            keyStore.load(null, null);
            keyStore.setCertificateEntry(Integer.toString(1), certificate);

            final TrustManagerFactory tmf = TrustManagerFactory.getInstance(
                TrustManagerFactory.getDefaultAlgorithm());

            tmf.init(keyStore);

            final SSLContext context = SSLContext.getInstance("TLS");

            context.init(null, tmf.getTrustManagers(), null);

            return context;
        }
    }
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:28,代码来源:LoggingTasks.java

示例4: openInputStream

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public InputStream openInputStream() throws IOException {

    boolean zip = url.toString().endsWith(".zip");

    ByteSource byteSource = Resources.asByteSource(url);

    if (zip) {
        byteSource = unzipSource(byteSource);
    }

    return byteSource.openBufferedStream();

}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:15,代码来源:URLMynlpResource.java

示例5: openLineReader

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public CharSourceLineReader openLineReader() {

    boolean zip = url.toString().endsWith(".zip");

    ByteSource byteSource = Resources.asByteSource(url);

    if (zip) {
        byteSource = unzipSource(byteSource);
    }

    CharSource charSource = byteSource.asCharSource(charset);

    return new CharSourceLineReader(charSource);
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:16,代码来源:URLMynlpResource.java

示例6: asByteSource

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final ByteSource asByteSource() {
  return Resources.asByteSource(url());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:ClassPath.java


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