Java InputStream to OutputStream inputStreamToOutputStream(InputStream is, OutputStream os)

Here you can find the source of inputStreamToOutputStream(InputStream is, OutputStream os)

Description

copy of an inputstream to corresponding outputStream be carefull on using this method

License

Open Source License

Parameter

Parameter Description
is the input stream to read

Exception

Parameter Description
IOException an exception

Declaration

public static void inputStreamToOutputStream(InputStream is, OutputStream os) throws IOException 

Method Source Code

//package com.java2s;
/*/* w w  w  . j a  v a2 s  . co  m*/
 * Copyright (C) 2010 - 2012 Jenia Software.
 *
 * This file is part of Sinekarta
 *
 * Sinekarta 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 3 of the License, or
 * (at your option) any later version.
 *
 * Sinekarta 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.
 *
 */

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

public class Main {
    /**
     * copy of an inputstream to corresponding outputStream
     * be carefull on using this method
     * 
     * @param is the input stream to read
     * @throws IOException
     */
    public static void inputStreamToOutputStream(InputStream is, OutputStream os) throws IOException {
        byte[] buf = new byte[8192];
        int len = is.read(buf);
        while (len >= 0) {
            os.write(buf, 0, len);
            os.flush();
            len = is.read(buf);
        }
        is.close();
        os.flush();
        os.close();
    }
}

Related

  1. copyStreamToStream(InputStream in, OutputStream out)
  2. inputStreamToOutputStream(final InputStream in, final OutputStream out)
  3. inputStreamToOutputStream(final InputStream in, final OutputStream out, int buffer)
  4. inputStreamToOutputStream(final InputStream inputStream, final OutputStream outputStream)
  5. inputStreamToOutputStream(InputStream inStream, OutputStream outStream)