Here you can find the source of copyStream(InputStream is, OutputStream os)
public static void copyStream(InputStream is, OutputStream os)
//package com.java2s; /*/*from w w w . j av a2s . c om*/ * Copyright 2016 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void copyStream(InputStream is, OutputStream os) { byte[] buf = new byte[8192]; int rc; try (InputStream input = is) { while ((rc = input.read(buf)) != -1) { os.write(buf, 0, rc); } } catch (Exception e) { throw new RuntimeException("Failed to read/write a stream: ", e); } finally { try { os.flush(); } catch (IOException e) { throw new RuntimeException("Failed to write a stream: ", e); } } } }