Java InputStream to OutputStream copyStream(InputStream input, OutputStream output)

Here you can find the source of copyStream(InputStream input, OutputStream output)

Description

Writes the content of input into output

License

Open Source License

Parameter

Parameter Description
input The InputStream to be copied to
output The target OutputStream to copy to

Exception

Parameter Description
IOException If IOException is thrown

Return

The content of input

Declaration

public static String copyStream(InputStream input, OutputStream output) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*ww  w .  j a  va2 s  .c o  m*/
     * Writes the content of input into output
     * 
     * @param input
     *          The {@link InputStream} to be copied to
     * @param output
     *          The target {@link OutputStream} to copy to
     * @return The content of input
     * @throws IOException
     *           If IOException is thrown
     */
    public static String copyStream(InputStream input, OutputStream output) throws IOException {
        StringBuilder sb = new StringBuilder();
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
            sb.append(new String(buffer, 0, bytesRead));
        }
        return sb.toString();
    }
}

Related

  1. copyStream(InputStream in, OutputStream out, long maxLen)
  2. copyStream(InputStream in, OutputStream out, String end)
  3. copyStream(InputStream input, OutputStream output)
  4. copyStream(InputStream input, OutputStream output)
  5. copyStream(InputStream input, OutputStream output)
  6. copyStream(InputStream input, OutputStream output)
  7. copyStream(InputStream input, OutputStream output)
  8. copyStream(InputStream input, OutputStream output)
  9. copyStream(InputStream input, OutputStream output)