Here you can find the source of copyStream(InputStream input, OutputStream output)
Parameter | Description |
---|---|
input | The input stream. |
output | The output stream. |
Parameter | Description |
---|---|
IOException | An exception if an error occurs while processing either ofthe streams. |
static public int copyStream(InputStream input, OutputStream output) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w w w .ja v a 2 s.co m * IBM Corporation - initial API and implementation * yyyymmdd bug Email and other contact information * -------- -------- ----------------------------------------------------------- * 20060330 124667 kathy@ca.ibm.com - Kathy Chan * 20060421 136761 rsinha@ca.ibm.com - Rupam Kuehner * 20060424 115690 sengpl@ca.ibm.com - Seng Phung-Lu * 20060503 126819 rsinha@ca.ibm.com - Rupam Kuehner * 20080122 215866 trungha@ca.ibm.com - Trung Ha * 20080303 218696 ericdp@ca.ibm.com - Eric D. Peters, APIs using EJBArtifactEdit not able to deal with some EJB 3.0 beans properly * 20080626 236645 kathy@ca.ibm.com - Kathy Chan * 20110824 355771 kchong@ca.ibm.com - Keith Chong, Remove unused/dead code as reported in build reports *******************************************************************************/ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copies data from one stream to another. * * @param input * The input stream. * @param output * The output stream. * @return The number of bytes copied. * @throws IOException * An exception if an error occurs while processing either of * the streams. */ static public int copyStream(InputStream input, OutputStream output) throws IOException { int t = 0; byte[] buffer = new byte[1024]; int n = input.read(buffer); while (n >= 0) { output.write(buffer, 0, n); t += n; n = input.read(buffer); } return t; } }