52 lines
1.9 KiB
Java
52 lines
1.9 KiB
Java
|
package org.schabi.newpipe.util;
|
||
|
|
||
|
import java.io.BufferedInputStream;
|
||
|
import java.io.FileInputStream;
|
||
|
import java.util.zip.ZipEntry;
|
||
|
import java.util.zip.ZipOutputStream;
|
||
|
|
||
|
/**
|
||
|
* Created by Christian Schabesberger on 28.01.18.
|
||
|
* Copyright 2018 Christian Schabesberger <chris.schabesberger@mailbox.org>
|
||
|
* ZipHelper.java is part of NewPipe
|
||
|
*
|
||
|
* License: GPL-3.0+
|
||
|
* This program 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.
|
||
|
*
|
||
|
* 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 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/>.
|
||
|
*/
|
||
|
|
||
|
public class ZipHelper {
|
||
|
|
||
|
private static final int BUFFER_SIZE = 2048;
|
||
|
|
||
|
/**
|
||
|
* This function helps to create zip files
|
||
|
* @param outZip The ZipOutputStream where the data should be stored in
|
||
|
* @param file The path of the file that should be added to zip.
|
||
|
* @param name The path of the file inside the zip.
|
||
|
* @throws Exception
|
||
|
*/
|
||
|
public static void addFileToZip(ZipOutputStream outZip, String file, String name) throws Exception {
|
||
|
byte data[] = new byte[BUFFER_SIZE];
|
||
|
FileInputStream fi = new FileInputStream(file);
|
||
|
BufferedInputStream inputStream = new BufferedInputStream(fi, BUFFER_SIZE);
|
||
|
ZipEntry entry = new ZipEntry(name);
|
||
|
outZip.putNextEntry(entry);
|
||
|
int count;
|
||
|
while((count = inputStream.read(data, 0, BUFFER_SIZE)) != -1) {
|
||
|
outZip.write(data, 0, count);
|
||
|
}
|
||
|
inputStream.close();
|
||
|
}
|
||
|
}
|