Here you can find the source of copyStream(InputStream src, OutputStream osstream)
public static boolean copyStream(InputStream src, OutputStream osstream) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (C) 2005-2012 Alfresco Software Limited. * /* w w w .j a v a2 s . c o m*/ * This file is part of the Alfresco Mobile SDK. * * 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.*; public class Main { public static final int MAX_BUFFER_SIZE = 1024; public static boolean copyStream(InputStream src, OutputStream osstream) throws IOException { BufferedOutputStream bos = null; BufferedInputStream bis = null; boolean copied = true; try { bos = new BufferedOutputStream(osstream); bis = new BufferedInputStream(src); byte[] buffer = new byte[MAX_BUFFER_SIZE]; int count; while ((count = bis.read(buffer)) != -1) { bos.write(buffer, 0, count); } bos.flush(); } catch (IOException e) { copied = false; throw e; } finally { closeStream(osstream); closeStream(src); closeStream(bis); } return copied; } public static void closeStream(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { // Ignore } } } }