Java InputStream to OutputStream copyStream(InputStream in, FileOutputStream out, IProgressMonitor monitor, int length)

Here you can find the source of copyStream(InputStream in, FileOutputStream out, IProgressMonitor monitor, int length)

Description

copy Stream

License

Open Source License

Declaration

private static void copyStream(InputStream in, FileOutputStream out, IProgressMonitor monitor, int length)
            throws IOException 

Method Source Code


//package com.java2s;
/*/* w w  w .j a va 2  s .  c om*/
 * Copyright (c) 2014, the Dart project authors.
 * 
 * Licensed under the Eclipse Public License v1.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.eclipse.org/legal/epl-v10.html
 * 
 * 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 org.eclipse.core.runtime.IProgressMonitor;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static void copyStream(InputStream in, FileOutputStream out, IProgressMonitor monitor, int length)
            throws IOException {
        byte[] data = new byte[4096];

        int count = in.read(data);

        while (count != -1) {
            out.write(data, 0, count);

            if (length != -1) {
                monitor.worked(count);
            }

            count = in.read(data);
        }

        in.close();
        out.close();
    }
}

Related

  1. copyStream(final OutputStream to, final InputStream from)
  2. copyStream(InputStream fis, OutputStream fos)
  3. copyStream(InputStream from, OutputStream to)
  4. copyStream(InputStream in, boolean closeIn, OutputStream out, boolean closeOut)
  5. copyStream(InputStream in, File outputFile)
  6. copyStream(InputStream in, OutputStream os)
  7. copyStream(InputStream in, OutputStream os)
  8. copyStream(InputStream in, OutputStream out)
  9. copyStream(InputStream in, OutputStream out)