本文整理匯總了Java中com.google.common.io.ByteSource.asCharSource方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteSource.asCharSource方法的具體用法?Java ByteSource.asCharSource怎麽用?Java ByteSource.asCharSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.io.ByteSource
的用法示例。
在下文中一共展示了ByteSource.asCharSource方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.google.common.io.ByteSource; //導入方法依賴的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: openLineReader
import com.google.common.io.ByteSource; //導入方法依賴的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);
}
示例3: openLineReader
import com.google.common.io.ByteSource; //導入方法依賴的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);
}