下面列出了com.google.common.io.InputSupplier#com.google.common.io.OutputSupplier 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void downloadZip(String url, File targetZip) {
if (targetZip.exists()) {
return;
}
File zipTemp = new File(targetZip.getAbsolutePath() + ".temp");
try {
zipTemp.getParentFile().mkdirs();
InputSupplier<InputStream> input = Resources
.newInputStreamSupplier(URI.create(url).toURL());
OutputSupplier<FileOutputStream> ouput = Files
.newOutputStreamSupplier(zipTemp);
ByteStreams.copy(input, ouput);
} catch (IOException e) {
String message = "Unable to download phantomjs from " + url;
throw new IllegalStateException(message, e);
}
zipTemp.renameTo(targetZip);
}
private void downloadZip(String url, File targetZip) {
if (targetZip.exists()) {
return;
}
File zipTemp = new File(targetZip.getAbsolutePath() + ".temp");
try {
zipTemp.getParentFile().mkdirs();
InputSupplier<InputStream> input = Resources
.newInputStreamSupplier(URI.create(url).toURL());
OutputSupplier<FileOutputStream> ouput = Files
.newOutputStreamSupplier(zipTemp);
ByteStreams.copy(input, ouput);
} catch (IOException e) {
String message = "Unable to download phantomjs from " + url;
throw new IllegalStateException(message, e);
}
zipTemp.renameTo(targetZip);
}
private void downloadZip(String url, File targetZip) {
if (targetZip.exists()) {
return;
}
File zipTemp = new File(targetZip.getAbsolutePath() + ".temp");
try {
zipTemp.getParentFile().mkdirs();
InputSupplier<InputStream> input = Resources
.newInputStreamSupplier(URI.create(url).toURL());
OutputSupplier<FileOutputStream> ouput = Files
.newOutputStreamSupplier(zipTemp);
ByteStreams.copy(input, ouput);
} catch (IOException e) {
String message = "Unable to download phantomjs from " + url;
throw new IllegalStateException(message, e);
}
zipTemp.renameTo(targetZip);
}
private void saveArguments(Arguments arguments, final Path targetPath) throws IOException {
LOG.debug("Creating {}", targetPath);
ArgumentsCodec.encode(arguments, new OutputSupplier<Writer>() {
@Override
public Writer getOutput() throws IOException {
return Files.newBufferedWriter(targetPath, StandardCharsets.UTF_8);
}
});
LOG.debug("Done {}", targetPath);
}
public static void encode(Arguments arguments, OutputSupplier<? extends Writer> writerSupplier) throws IOException {
try (Writer writer = writerSupplier.getOutput()) {
GSON.toJson(arguments, writer);
}
}