Java FileOutputStream Create writeFileToOutputStream(ZipInputStream zipInputStream, File outputFile)

Here you can find the source of writeFileToOutputStream(ZipInputStream zipInputStream, File outputFile)

Description

Writes a ZipInputStream to a File.

License

Open Source License

Parameter

Parameter Description
zipInputStream the stream to read
outputFile the <code>File</code> to write to

Exception

Parameter Description
IOException If an input or output exception occurred

Declaration

public static void writeFileToOutputStream(ZipInputStream zipInputStream, File outputFile) throws IOException 

Method Source Code

//package com.java2s;
/*/*from   w w w  . j  av  a  2 s  .  co  m*/
 *  This file is part the Cytobank ACS Library.
 *  Copyright (C) 2010 Cytobank, Inc.  All rights reserved.
 *
 *  The Cytobank ACS Library program is free software: 
 *  you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

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

import java.util.zip.ZipInputStream;

public class Main {
    /** The buffer size in bytes to create when copying streams. */
    public static final int BYTE_BUFFER_SIZE = 1024000;

    /**
     * Writes a <code>ZipInputStream</code> to a <code>File</code>.
     * 
     * @param zipInputStream the stream to read
     * @param outputFile the <code>File</code> to write to
     * @throws IOException If an input or output exception occurred
     */
    public static void writeFileToOutputStream(ZipInputStream zipInputStream, File outputFile) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
        try {
            writeInputStreamToOutputStream(zipInputStream, fileOutputStream);
        } finally {
            try {
                fileOutputStream.close();
            } catch (Throwable ignore) {
            }
        }
    }

    /**
     * Writes an <code>InputStream</code> to an <code>OutputStream</code>.
     * 
     * @param inputStream the <code>InputStream</code> to read
     * @param outputStream the <code>OutputStream</code> to write to
     * @return the number of bytes written
     * @throws IOException If an input or output exception occurred
     */
    public static long writeInputStreamToOutputStream(InputStream inputStream, OutputStream outputStream)
            throws IOException {
        final byte[] byteBuffer = new byte[BYTE_BUFFER_SIZE];

        int read;
        long written = 0;

        while ((read = inputStream.read(byteBuffer, 0, BYTE_BUFFER_SIZE)) > 0) {
            outputStream.write(byteBuffer, 0, read);
            written += read;
        }

        return written;
    }
}

Related

  1. writeFileRaw(String fileName, byte[][] contents)
  2. writeFileToByte(byte[] bytes, File file)
  3. writeFileToDisk(ByteArrayOutputStream is, String savePath)
  4. writeFileToDisk(File file, String targetPath)
  5. writeFileToFile(File inFile, File toFile)
  6. writeFileUTF8(final File file, final String contents)
  7. writeFileWithParent(File file, String contentStr, String charset)
  8. writeFileWithParent(String filename, byte[] content)
  9. writeFileWithParent(String filename, String contentStr, String charset)