Java InputStream Copy to File copyStreamsToFolder(Iterator> streams, File folder)

Here you can find the source of copyStreamsToFolder(Iterator> streams, File folder)

Description

copy Streams To Folder

License

Open Source License

Declaration

public static void copyStreamsToFolder(Iterator<Map.Entry<String, InputStream>> streams, File folder)
            throws IOException 

Method Source Code

//package com.java2s;
/**// w  ww . j  a va2 s. co m
 * Created by Andrew Reslan.
 * <p/>
 * Copyright (c) 2012 Couchbase, Inc. All rights reserved.
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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.*;
import java.util.Iterator;
import java.util.Map;

public class Main {
    public static void copyStreamsToFolder(Iterator<Map.Entry<String, InputStream>> streams, File folder)
            throws IOException {

        while (streams.hasNext()) {
            Map.Entry<String, InputStream> entry = streams.next();
            File file = new File(folder, entry.getKey());
            copyStreamToFile(entry.getValue(), file);
        }
    }

    public static void copyStreamToFile(InputStream is, File file) throws IOException {

        OutputStream os = new FileOutputStream(file);
        int n;
        byte[] buffer = new byte[16384];
        while ((n = is.read(buffer)) > -1) {
            os.write(buffer, 0, n);
        }
        os.close();
        is.close();
    }
}

Related

  1. copyStream(InputStream copyFrom, File copyTo)
  2. copyStream(InputStream in, File dest)
  3. copyStream(InputStream in, File dest)
  4. copyStreamIntoFile(File outFile, InputStream is)
  5. copyStreamsToFile(String path, Map streamMap)
  6. copyStreamToFile(final File to, final InputStream from)
  7. copyStreamToFile(InputStream from, File to)
  8. copyStreamToFile(InputStream in, File destination)
  9. copyStreamToFile(InputStream in, File out)