我可以通过此异常检查流值是否为 null:
(空!= 供应商)
或者我需要检查:
(null != readerSupplier.getInput())
我应该刷新()输出流吗?看评论。
公共无效运行(){
try {
final Process process = Runtime.getRuntime().exec("su");
InputSupplier<InputStreamReader> readerSupplier = CharStreams.newReaderSupplier(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return process.getInputStream();
}
}, Charsets.UTF_8);
OutputSupplier<OutputStreamWriter> writerSupplier = CharStreams.newWriterSupplier(new OutputSupplier<OutputStream>() {
@Override
public OutputStream getOutput() throws IOException {
return process.getOutputStream();
}
}, Charsets.UTF_8);
// can I check the stream objects for null readerSupplier/writerSupplier?
// or need: readerSupplier.getInput()/writerSupplier.getOutput()?
if (null != readerSupplier && null != writerSupplier) {
...
CharStreams.write(someCommand, writerSupplier);
// should I flush() output stream? How better? Flushables.flush(writerSupplier) or Flushables.flush(writerSupplier.getOutput())
}