Created
March 28, 2013 03:16
-
-
Save fitzyyf/5260276 to your computer and use it in GitHub Desktop.
Google Guava Stream to String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FSDataInputStream,支持随机访问 | |
final FSDataInputStream in = fs.open(new Path(hdfs_file_uri)); | |
try { | |
// 设置从第八行开始读取 | |
InputSupplier<? extends InputStream> supplier = new InputSupplier<InputStream>() { | |
@Override | |
public InputStream getInput() throws IOException { | |
return in; | |
} | |
}; | |
final InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(supplier, Charsets.UTF_8); | |
String text = CharStreams.toString(readerSupplier); | |
System.out.println(text); | |
Assert.assertTrue(text.startsWith("nginx是一个高性能的Http和反向代理服务")); | |
} finally { | |
IOUtils.closeStream(in); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment