Copy from input stream to output stream

@param input
@param output
@return this request
@throws java.io.IOException
503793
protected OkRequest<T> copy(final InputStream input, final OutputStream output) throws IOException {
        return new CloseOperation<OkRequest>(input, mIgnoreCloseExceptions) {

            @Override
            public OkRequest<T> call() throws IOException {
                boolean thrown = false;
                try {
                    final byte[] buffer = new byte[mBufferSize];
                    int read;
                    while ((read = input.read(buffer)) != -1) {
                        output.write(buffer, 0, read);
                    }
                    return OkRequest.this;
                } catch (IOException e) {
                    thrown = true;
                    throw e;
                } finally {
                    try {
                        done();
                    } catch (IOException e) {
                        if (!thrown) {
                            throw e;
                        }
                    }

                }

            }
        }.call();
    }
224602
public static void copyStream(InputStream from, OutputStream to) throws IOException {
        byte buffer[] = new byte[2048];
        int bytesRead;
        while ((bytesRead = from.read(buffer)) != -1) {
            to.write(buffer, 0, bytesRead);
        }
        from.close();
    }
881913
public long copyTo(OutputStream output) throws IOException {
    checkNotNull(output);

    Closer closer = Closer.create();
    try {
      InputStream in = closer.register(openStream());
      return ByteStreams.copy(in, output);
    } catch (Throwable e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }
  }
1029387
public void execute(InputStream input, OutputStream output) throws IOException {
        execute(input, output, null);
    }
864803
public static byte[] readByteArray(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output);
        return output.toByteArray();
    }
135915
public long copy(InputStream in, OutputStream out) throws IOException {
        return copy(in, out, Integer.MAX_VALUE);
    }
374894
public static void streamCopy(InputStream input, Writer output) throws IOException
	{
		if (input == null)
			throw new IllegalArgumentException("Must provide something to read from");
		if (output == null)
			throw new IllegalArgumentException("Must provide something to write to");

		streamCopy(new InputStreamReader(input), output);
	}
1299639
public static int copy(File in, File out) throws IOException {
		Assert.notNull(in, "No input File specified");
		Assert.notNull(out, "No output File specified");
		return copy(new BufferedInputStream(new FileInputStream(in)),
			new BufferedOutputStream(new FileOutputStream(out)));
	}
1273505
public static void copy(final InputStream in, final OutputStream out)
			throws IOException {
		copy(in, out, DEFAULT_BUFFER_SIZE);
	}
645301
public static void copy(InputStream in,
			OutputStream out) throws IOException {
		copy(in, out, false);
	}
99592
public static void copyThenClose(InputStream input, OutputStream output)
      throws IOException {
    copy(input, output);
    input.close();
    output.close();
  }
745850
private void copy(OutputStream out, File in) throws IOException {
        FileInputStream inStream = null;
        try {
            inStream = new FileInputStream(in);

            byte[] buffer = new byte[4096];
            int len;
            while ((len = inStream.read(buffer)) != -1) {
                out.write(buffer, 0, len);
            }
        } finally {
            if (inStream != null) {
                inStream.close();
            }
        }
    }
784226
public static void copy(String in, Charset charset, OutputStream out) throws IOException {
		Assert.notNull(in, "No input String specified");
		Assert.notNull(charset, "No charset specified");
		Assert.notNull(out, "No OutputStream specified");
		Writer writer = new OutputStreamWriter(out, charset);
		writer.write(in);
		writer.flush();
	}
100606
public static long copy(InputStream input, OutputStream output) throws IOException {
        byte[] buffer = new byte[2 * 1024];
        long total = 0;
        int count;
        while ((count = input.read(buffer)) != -1) {
            output.write(buffer, 0, count);
            total += count;
        }

        return total;
    }
416734
public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
    LOGGER.trace("copy(InputStream, OutputStream)");
    copy(inputStream, outputStream, new byte[BUFFER_SIZE]);
  }
1091278
public static int copy(InputStream in, OutputStream out) throws IOException {
		Assert.notNull(in, "No InputStream specified");
		Assert.notNull(out, "No OutputStream specified");
		try {
			return StreamUtils.copy(in, out);
		}
		finally {
			try {
				in.close();
			}
			catch (IOException ex) {
			}
			try {
				out.close();
			}
			catch (IOException ex) {
			}
		}
	}
426568
public static void copy(InputStream in, OutputStream out, long byteCount) throws IOException {
        byte buffer[] = new byte[bufferSize];
        int len = bufferSize;

        if (byteCount >= 0) {
            while (byteCount > 0) {
                int max = byteCount < bufferSize ? (int) byteCount : bufferSize;
                len = in.read(buffer, 0, max);

                if (len == -1)
                    break;

                byteCount -= len;
                out.write(buffer, 0, len);
            }
        } else {
            while (true) {
                len = in.read(buffer, 0, bufferSize);
                if (len < 0)
                    break;
                out.write(buffer, 0, len);
            }
        }
    }