Here you can find the source of copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
public static void copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws IOException
//package com.java2s; /*/* ww w.jav a 2 s .com*/ * DBeaver - Universal Database Manager * Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (version 2) * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ import java.io.*; public class Main { public static final int DEFAULT_BUFFER_SIZE = 16384; public static void copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws IOException { copyStream(inputStream, outputStream, DEFAULT_BUFFER_SIZE); } /** Read entire input stream and writes all data to output stream then closes input and flushed output */ public static void copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream, int bufferSize) throws IOException { try { byte[] writeBuffer = new byte[bufferSize]; for (int br = inputStream.read(writeBuffer); br != -1; br = inputStream .read(writeBuffer)) { outputStream.write(writeBuffer, 0, br); } outputStream.flush(); } finally { // Close input stream inputStream.close(); } } public static void close(Closeable closeable) { try { closeable.close(); } catch (IOException e) { e.printStackTrace(); } } }