Shai! here is my contribution for a future zip/unzip class
import com.codename1.io.FileSystemStorage;
import com.codename1.io.Log;
import com.codename1.io.Storage;
import com.codename1.ui.Display;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.sf.zipme.ZipEntry;
import net.sf.zipme.ZipInputStream;
/**
*
* @author roman
*/
public class Unzip {
public Unzip(String zipName, String dirDest) {
InputStream is;
try {
is = Storage.getInstance().createInputStream(zipName);
ZipInputStream zipStream = new ZipInputStream(is);
ZipEntry entry;
// create a buffer to improve copy performance later.
byte[] buffer = new byte[2048];
while ((entry = zipStream.getNextEntry()) != null) {
String s = entry.getName();
// System.out.println(s);
// Once we get the entry from the stream, the stream is
// positioned read to read the raw data, and we keep
// reading until read returns 0 or less.
String outdir =
FileSystemStorage.getInstance().getAppHomePath();
if (outdir.length() > 0)
{
outdir = outdir + "/" + dirDest;
}
String outpath = outdir + "/" + entry.getName();
OutputStream output = null;
try {
output =
FileSystemStorage.getInstance().openOutputStream(outpath);
int len = 0;
while ((len = zipStream.read(buffer)) > 0) {
output.write(buffer, 0, len);
}
} finally {
// we must always close the output file
if (output != null) {
output.close();
}
}
}
} catch (IOException ex) {
Log.p(ex.getMessage(), 0);
}
}
/**
* Unzip from stream
* @param zipFile
* @param dirDest
*/
public Unzip(InputStream zipFile, String dirDest) {
InputStream is;
try {
is = zipFile;
ZipInputStream zipStream = new ZipInputStream(is);
ZipEntry entry;
// create a buffer to improve copy performance later.
byte[] buffer = new byte[2048];
while ((entry = zipStream.getNextEntry()) != null) {
String s = entry.getName();
String outdir =
FileSystemStorage.getInstance().getAppHomePath();
if (outdir.length() > 0)
{
outdir = outdir + "/" + dirDest;
}
String outpath = outdir + "/" + entry.getName();
OutputStream output = null;
try {
output =
FileSystemStorage.getInstance().openOutputStream(outpath);
int len = 0;
while ((len = zipStream.read(buffer)) > 0) {
output.write(buffer, 0, len);
}
} finally {
// we must always close the output file
if (output != null) {
output.close();
}
}
}
} catch (IOException ex) {
Log.p(ex.getMessage(), 0);
}
}
}
On Saturday, May 27, 2017 at 2:36:13 AM UTC-3, Shai Almog wrote:
>
> I only wrote some code to compress a zip not decompress. It's in the skin
> designer project.
>
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/5ebb55e8-0986-4408-ac3e-ef8b93add5a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.