Java InputStream to OutputStream copyStream(InputStream inStream, OutputStream outStream)

Here you can find the source of copyStream(InputStream inStream, OutputStream outStream)

Description

copy Stream

License

Open Source License

Declaration

private static void copyStream(InputStream inStream,
            OutputStream outStream) throws IOException 

Method Source Code

//package com.java2s;
/*/*from w ww .  j  av  a 2 s  .co m*/
 * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
 * subject to license terms.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the Lesser 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 */

import java.io.InputStream;
import java.io.OutputStream;

import java.io.IOException;

public class Main {
    private static void copyStream(InputStream inStream,
            OutputStream outStream) throws IOException {
        int readbytes = 0;

        try {
            do {
                byte[] buffer = new byte[512];
                readbytes = inStream.read(buffer, 0, 512);
                if (readbytes <= 0) {
                    break;
                }

                outStream.write(buffer, 0, readbytes);
                outStream.flush();
            } while (true);
        } catch (IOException ioE) {
            ioE.printStackTrace();
        } finally {
            if (inStream != null) {
                inStream.close();
            }
            if (outStream != null) {
                outStream.close();
            }
        }
    }
}

Related

  1. copyStream(InputStream input, OutputStream output, int bufferSize)
  2. copyStream(InputStream input, OutputStream output, int length)
  3. copyStream(InputStream inputStream, OutputStream outputStream)
  4. copyStream(InputStream inputStream, OutputStream outputStream)
  5. copyStream(InputStream inStream, OutputStream outStream)
  6. copyStream(InputStream is, OutputStream os)
  7. copyStream(InputStream is, OutputStream os)
  8. copyStream(InputStream is, OutputStream os)
  9. copyStream(InputStream is, OutputStream os)