Java ZipOutputStream Write zipFile(ZipOutputStream zos, File file, String requestName, byte[] buf)

Here you can find the source of zipFile(ZipOutputStream zos, File file, String requestName, byte[] buf)

Description

zip File

License

Open Source License

Declaration

public static String zipFile(ZipOutputStream zos, File file, String requestName, byte[] buf)
            throws IOException 

Method Source Code

//package com.java2s;
/*//from ww w. jav a2 s  .  c  o m
SongScribe song notation program
Copyright (C) 2006 Csaba Kavai
    
This file is part of SongScribe.
    
SongScribe is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
    
SongScribe 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 General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
Created on Aug 6, 2006
*/

import java.io.*;

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    public static String zipFile(ZipOutputStream zos, File file, String requestName, byte[] buf)
            throws IOException {
        String fileName = requestName == null ? file.getName() : requestName;
        zos.putNextEntry(new ZipEntry(fileName));
        FileInputStream fis = new FileInputStream(file);
        int read;

        while ((read = fis.read(buf)) > 0) {
            zos.write(buf, 0, read);
        }

        fis.close();
        return fileName;
    }
}

Related

  1. zipFile(ZipOutputStream out, File file, String dir)
  2. zipFile(ZipOutputStream out, File sourceFile)
  3. zipFile(ZipOutputStream out, String stripPath, File file, char pathSeparator)
  4. zipFile(ZipOutputStream zipOut, String path, File file)
  5. zipFile(ZipOutputStream zos, BufferedOutputStream out, File destPath, String originalPath)
  6. zipFile(ZipOutputStream zout, File file, int rootLength)
  7. zipInternal(String path, File file, ZipOutputStream os)
  8. zipInternal(String path, File file, ZipOutputStream os, boolean justFolders, boolean skipManifest)
  9. zipIt(ZipOutputStream zos, String[] directoriesAndFiles, CRC32 crc)