本文整理汇总了Java中com.google.common.io.Files.asByteSource方法的典型用法代码示例。如果您正苦于以下问题:Java Files.asByteSource方法的具体用法?Java Files.asByteSource怎么用?Java Files.asByteSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Files
的用法示例。
在下文中一共展示了Files.asByteSource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* @param testFilePaths paths to files containing testcases.
*/
public static void main(String... testFilePaths) throws IOException {
int testCount = 0;
for (String testFilePath : testFilePaths) {
File testFile = new File(testFilePath);
ByteSource bytes = Files.asByteSource(testFile);
// Just read bytes as chars since the URL grammar is an octet-based grammar.
CharSource chars = bytes.asCharSource(Charsets.ISO_8859_1);
String input = chars.read();
boolean ok = false;
try {
UrlValue url = UrlValue.from(input);
url.getAuthority(Diagnostic.Receiver.NULL);
url.getContentMediaType();
url.getContentMetadata();
url.getDecodedContent();
url.getFragment();
url.getQuery();
url.getRawAuthority();
url.getRawContent();
url.getRawPath();
ok = true;
} finally {
if (!ok) {
System.err.println("Failed on `" + input + "` from " + testFilePath);
}
}
testCount += 1;
}
System.out.println("Ran " + testCount + " tests");
if (testCount == 0) {
throw new Error("No tests read");
}
}
示例2: openInputStream
import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public InputStream openInputStream() throws IOException {
boolean zip = file.getName().endsWith(".zip");
ByteSource byteSource = Files.asByteSource(file);
if (zip) {
byteSource = unzipSource(byteSource);
}
return byteSource.openBufferedStream();
}
示例3: openLineReader
import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public CharSourceLineReader openLineReader() {
boolean zip = file.getName().endsWith(".zip");
ByteSource byteSource = Files.asByteSource(file);
if (zip) {
byteSource = unzipSource(byteSource);
}
CharSource charSource = byteSource.asCharSource(charset);
return new CharSourceLineReader(charSource);
}