Java InputStream to OutputStream copyStreams(InputStream source, OutputStream target)

Here you can find the source of copyStreams(InputStream source, OutputStream target)

Description

Copies the contents of the source stream to the target stream.

License

Open Source License

Declaration

public static void copyStreams(InputStream source, OutputStream target) throws IOException 

Method Source Code


//package com.java2s;
/* -----------------------------------------------------------------------------
 * Antenna - An Ant-to-end solution for wireless Java 
 *
 * Copyright (c) 2002-2004 Joerg Pleumann <joerg@pleumann.de>
 * //from   w ww. j a va 2s. com
 * This library 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 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.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * -----------------------------------------------------------------------------
 */

import java.io.*;

public class Main {
    /**
     * Copies the contents of the source stream to the target stream.
     */
    public static void copyStreams(InputStream source, OutputStream target) throws IOException {
        byte[] buffer = new byte[128];
        int i = source.read(buffer);
        while (i != -1) {
            target.write(buffer, 0, i);
            i = source.read(buffer);
        }
    }
}

Related

  1. copyStreams(InputStream in, OutputStream out, int buf)
  2. copyStreams(InputStream input, OutputStream output)
  3. copyStreams(InputStream inputStream, OutputStream outputStream)
  4. copyStreams(InputStream is, OutputStream os)
  5. copyStreams(InputStream source, OutputStream destination)
  6. copyStreamSafely(InputStream in, ByteArrayOutputStream os)
  7. copyStreamToFile(final InputStream stream, final File output)
  8. copyStreamToFile(InputStream input, String outputPath)
  9. CopyStreamToFile(InputStream inputStream, File outputFile)