util
Clone or download
Modified Files
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.iohelper;
package com.stream_pi.util.iohelper;
import java.io.File;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipInputStream;
public class IOHelper {
public class IOHelper
{
public static void unzip(InputStream inputStream, String destDir) throws Exception {
public static void unzip(InputStream inputStream, String destDir) throws IOException
{
File dir = new File(destDir);
File dir = new File(destDir);
// create output directory if it doesn't exist
if(!dir.exists()) dir.mkdirs();
if(!dir.exists()) dir.mkdirs();
InputStream fis;
InputStream fis;
//buffer for read and write data to file
byte[] buffer = new byte[1024];
byte[] buffer = new byte[1024];
fis = inputStream;
fis = inputStream;
ZipInputStream zis = new ZipInputStream(fis);
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry ze = zis.getNextEntry();
ZipEntry ze = zis.getNextEntry();
while(ze != null){
while(ze != null)
{
String fileName = ze.getName();
String fileName = ze.getName();
File newFile = new File(destDir + File.separator + fileName);
File newFile = new File(destDir + File.separator + fileName);
if(ze.isDirectory())
if(ze.isDirectory())
{
{
newFile.mkdirs();
newFile.mkdirs();
}
}
else
else
{
{
FileOutputStream fos = new FileOutputStream(newFile);
FileOutputStream fos = new FileOutputStream(newFile);
int len;
int len;
while ((len = zis.read(buffer)) > 0)
while ((len = zis.read(buffer)) > 0)
{
{
fos.write(buffer, 0, len);
fos.write(buffer, 0, len);
}
}
fos.close();
fos.close();
}
}
//close this ZipEntry
zis.closeEntry();
zis.closeEntry();
ze = zis.getNextEntry();
ze = zis.getNextEntry();
}
}
//close last ZipEntry
zis.closeEntry();
zis.closeEntry();
zis.close();
zis.close();
fis.close();
fis.close();
}
}
}
}