Here you can find the source of copyStreams(InputStream in, OutputStream out)
Parameter | Description |
---|---|
in | The stream to read data from |
out | The stream to write data to |
public static boolean copyStreams(InputStream in, OutputStream out)
//package com.java2s; /* Copyright (c) 2002-2011 by XMLVM.org * * Project Info: http://www.xmlvm.org//from www. j a v a 2 s . c o m * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * The actual procedure of copying Streams (like binary files) * * @param in * The stream to read data from * @param out * The stream to write data to * @return true, if everything is ok */ public static boolean copyStreams(InputStream in, OutputStream out) { if (in == null || out == null) return false; try { byte[] buf = new byte[4096]; int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len); in.close(); out.close(); return true; } catch (IOException e) { try { in.close(); } catch (IOException ex1) { } try { out.close(); } catch (IOException ex1) { } e.printStackTrace(); } return false; } }