Here you can find the source of copyStream(InputStream in, OutputStream out)
Parameter | Description |
---|---|
in | Input stream |
out | Output stream |
Parameter | Description |
---|---|
IOException | In case of a reading or writing error |
public static void copyStream(InputStream in, OutputStream out) throws IOException
//package com.java2s; /**// w ww. j a v a 2 s .c o m * Copyright 2009-2016 Three Crickets LLC. * <p> * The contents of this file are subject to the terms of the LGPL version 3.0: * http://www.gnu.org/copyleft/lesser.html * <p> * Alternatively, you can obtain a royalty free commercial license with less * limitations, transferable or non-transferable, directly from Three Crickets * at http://threecrickets.com/ */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copies streams. The input stream is entirely consumed and closed. * * @param in * Input stream * @param out * Output stream * @throws IOException * In case of a reading or writing error */ public static void copyStream(InputStream in, OutputStream out) throws IOException { in = new BufferedInputStream(in); try { out = new BufferedOutputStream(out); try { while (true) { int data = in.read(); if (data == -1) break; out.write(data); } } finally { out.flush(); } } finally { in.close(); } } }