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