-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Downloader for Card Images now working on Android version with Option…
…MenuButton (no zip)
- Loading branch information
valfieri
committed
Aug 19, 2019
1 parent
7cb0d8b
commit 73138d2
Showing
6 changed files
with
218 additions
and
56 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package net.wagic.utils; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
public class Zipper { | ||
|
||
private List <String> fileList; | ||
private String SOURCE_FOLDER; | ||
|
||
public Zipper(String source) { | ||
fileList = new ArrayList < String > (); | ||
SOURCE_FOLDER = source; | ||
} | ||
|
||
public void zipIt(String zipFile) { | ||
byte[] buffer = new byte[1024]; | ||
String source = new File(SOURCE_FOLDER).getName(); | ||
FileOutputStream fos = null; | ||
ZipOutputStream zos = null; | ||
try { | ||
fos = new FileOutputStream(zipFile); | ||
zos = new ZipOutputStream(fos); | ||
zos.setLevel(ZipOutputStream.STORED); | ||
System.out.println("Output to Zip : " + zipFile); | ||
FileInputStream in = null; | ||
|
||
for (String file: this.fileList) { | ||
System.out.println("File Added : " + file); | ||
ZipEntry ze = new ZipEntry(file); | ||
zos.putNextEntry(ze); | ||
try { | ||
in = new FileInputStream(SOURCE_FOLDER + File.separator + file); | ||
int len; | ||
while ((len = in .read(buffer)) > 0) { | ||
zos.write(buffer, 0, len); | ||
} | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
|
||
zos.closeEntry(); | ||
System.out.println("Folder successfully compressed"); | ||
|
||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} finally { | ||
try { | ||
zos.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public void generateFileList(File node) { | ||
// add file only | ||
if (node.isFile()) { | ||
fileList.add(generateZipEntry(node.toString())); | ||
} | ||
|
||
if (node.isDirectory()) { | ||
String[] subNote = node.list(); | ||
for (String filename: subNote) { | ||
generateFileList(new File(node, filename)); | ||
} | ||
} | ||
} | ||
|
||
private String generateZipEntry(String file) { | ||
return file.substring(SOURCE_FOLDER.length(), file.length()); | ||
} | ||
} |
Oops, something went wrong.