Here you can find the source of inputStreamToOutputStream(final InputStream in, final OutputStream out)
Parameter | Description |
---|---|
in | The stream to read. |
out | The stream to write. |
Parameter | Description |
---|---|
IOException | If problems occur. |
public static void inputStreamToOutputStream(final InputStream in, final OutputStream out) throws IOException
//package com.java2s; /*//ww w.j a v a 2s .c om * Copyright (c) 2003 Stephan D. Cote' - All rights reserved. * * This program and the accompanying materials are made available under the * terms of the MIT License which accompanies this distribution, and is * available at http://creativecommons.org/licenses/MIT/ * * Contributors: * Stephan D. Cote * - Initial concept and implementation */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** Size of block used in IO (4096 bytes) */ static final int CHUNK_SIZE = 4096; /** * Copy an input stream completely to an output stream. * * @param in The stream to read. * @param out The stream to write. * * @throws IOException If problems occur. */ public static void inputStreamToOutputStream(final InputStream in, final OutputStream out) throws IOException { byte[] buffer = null; boolean streaming = true; while (streaming) { buffer = new byte[CHUNK_SIZE]; final int count = in.read(buffer); if (count == -1) { streaming = false; } else { if (count < CHUNK_SIZE) { streaming = false; } out.write(buffer, 0, count); } } } }