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