Here you can find the source of CopyStream(InputStream sSource, OutputStream sTarget)
public static void CopyStream(InputStream sSource, OutputStream sTarget) throws IOException
//package com.java2s; /*/*from w w w. ja v a 2 s . c o m*/ KeePass Password Safe - The Open-Source Password Manager Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.io.*; public class Main { public static void CopyStream(InputStream sSource, OutputStream sTarget) throws IOException { assert (sSource != null && (sTarget != null)); if (sSource == null) throw new IllegalArgumentException("sSource"); if (sTarget == null) throw new IllegalArgumentException("sTarget"); final int nBufSize = 4096; byte[] pbBuf = new byte[nBufSize]; int read; while ((read = sSource.read(pbBuf, 0, nBufSize)) != -1) { sTarget.write(pbBuf, 0, read); } // Do not close any of the streams } public static byte[] Read(InputStream s, int nCount) throws IOException { if (s == null) throw new IllegalArgumentException("s"); if (nCount < 0) throw new ArrayIndexOutOfBoundsException("nCount"); byte[] pb = new byte[nCount]; int iOffset = 0; while (nCount > 0) { int iRead = s.read(pb, iOffset, nCount); if (iRead == -1) break; iOffset += iRead; nCount -= iRead; } if (iOffset != pb.length) { byte[] pbPart = new byte[iOffset]; System.arraycopy(pb, 0, pbPart, 0, iOffset); return pbPart; } return pb; } public static void Write(OutputStream s, byte[] pbData) throws IOException { if (s == null) { assert false; return; } if (pbData == null) { assert false; return; } s.write(pbData, 0, pbData.length); } }