Here you can find the source of copyStream(final InputStream is, final File destinationFile)
Parameter | Description |
---|---|
is | a parameter |
destinationFile | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static long copyStream(final InputStream is, final File destinationFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import com.google.common.io.ByteStreams; public class Main { private static final int BUF_SIZE = 1_024 * 1_024 * 1; /**/* w ww.j a v a2 s . co m*/ * Downloads to a temporary location and renames on finish so no partials * * @param is * @param destinationFile * @return * @throws IOException */ public static long copyStream(final InputStream is, final File destinationFile) throws IOException { final File tmpFile = File.createTempFile("flickr_download", null); try (final BufferedInputStream bis = new BufferedInputStream(is, BUF_SIZE); final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpFile), BUF_SIZE);) { final long total = ByteStreams.copy(bis, bos); tmpFile.renameTo(destinationFile); return total; } } }