Java InputStream to OutputStream copyStream(final InputStream is, final OutputStream os)

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

Description

Copy a stream to another location

License

Creative Commons License

Parameter

Parameter Description
is input stream
os output stream

Return

true if successful, false otherwise

Declaration

public static boolean copyStream(final InputStream is, final OutputStream os) 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

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

public class Main {
    /**/*from w w w  . jav a2 s  .co m*/
     * Copy a stream to another location
     *
     * @param is input stream
     * @param os output stream
     * @return true if successful, false otherwise
     */
    public static boolean copyStream(final InputStream is, final OutputStream os) {
        try {
            final byte[] buf = new byte[1024];

            int len;
            while ((len = is.read(buf)) > 0) {
                os.write(buf, 0, len);
            }
            is.close();
            os.close();
            return true;
        } catch (final IOException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. copyStream(final InputStream inputStream, final OutputStream out)
  2. copyStream(final InputStream inputStream, final OutputStream outputStream)
  3. copyStream(final InputStream inputStream, final OutputStream outputStream)
  4. copyStream(final InputStream inputStream, final OutputStream outputStream)
  5. copyStream(final InputStream is, final OutputStream os)
  6. copyStream(final InputStream is, final OutputStream out, final Long amount, final int bufferSize)
  7. copyStream(final InputStream source, final OutputStream target)
  8. copyStream(final InputStream src, OutputStream dest)
  9. copyStream(final OutputStream to, final InputStream from)