This is the actual function that compresses the files...
oh, and to you coders, before you say anything, I know, I know, big no no to have files as a classglobal variable I was still learning code design when writing this then again, I still am
Code: Select all
protected void compressFiles(File zip) throws IOException
{
ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(zip));
for (int i = 0; i<files.size(); i++)
{
byte b[] = new byte[512];
FileHolder fh = (FileHolder) files.get(i);
fh.setName(fh.getName().replace(File.separatorChar, '/'));
/* NOTE!!!!! it seems as if linux doesn't search for the correct cased names after
* all, but tried to find the lower case versions of the needed files... therefore,
* the .toLowerCase() will make sure that the all files in the .zip are in lowercase...
*/
ZipEntry ze = new ZipEntry(fh.getName().toLowerCase());
zo.putNextEntry(ze);
if (!ze.isDirectory())
{
int len = 0;
try
{
InputStream in = new FileInputStream(fh.getFile());
while ((len = in.read(b)) != -1)
{
zo.write(b,0,len);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
zo.closeEntry();
if (ze.getSize() > 0) sysout.print("Deflated ("+((ze.getCompressedSize()*100)/ze.getSize())+"%):\t"+fh.getName()+"...");
}
zo.close();
sysout.print("Done...");
}