类com.google.common.io.OutputSupplier源码实例Demo

下面列出了怎么用com.google.common.io.OutputSupplier的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: blog   文件: PhantomJsDownloader.java
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);
}
 
源代码2 项目: blog   文件: PhantomJsDownloader.java
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);
}
 
源代码3 项目: blog   文件: PhantomJsDownloader.java
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);
}
 
源代码4 项目: twill   文件: YarnTwillPreparer.java
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);
}
 
源代码5 项目: twill   文件: ArgumentsCodec.java
public static void encode(Arguments arguments, OutputSupplier<? extends Writer> writerSupplier) throws IOException {
  try (Writer writer = writerSupplier.getOutput()) {
    GSON.toJson(arguments, writer);
  }
}