From aead45c54b271e373a67cdde7004f6760f55593e Mon Sep 17 00:00:00 2001 From: pelya Date: Tue, 14 Sep 2010 18:28:12 +0300 Subject: [PATCH] Added AssetExtract.java by Renpytom - it's not used yet anywhere --- project/src/AssetExtract.java | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 project/src/AssetExtract.java diff --git a/project/src/AssetExtract.java b/project/src/AssetExtract.java new file mode 100644 index 000000000..2b4ce69b8 --- /dev/null +++ b/project/src/AssetExtract.java @@ -0,0 +1,105 @@ +// This string is autogenerated by ChangeAppSettings.sh, do not change +// spaces amount +package net.sourceforge.clonekeenplus; + +import java.util.zip.*; +import java.io.*; +import android.util.Log; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.content.res.AssetManager; + +class AssetExtract { + + private AssetManager mAssetManager = null; + + AssetExtract(AssetManager am) { + mAssetManager = am; + } + + + public boolean extract(String asset, String target) { + + byte buf[] = new byte[1024 * 1024]; + + InputStream assetStream = null; + + try { + assetStream = mAssetManager.open(asset, AssetManager.ACCESS_RANDOM); + } catch (IOException e) { + // TODO: Report error. + return false; + } + + ZipInputStream zip = new ZipInputStream(assetStream); + + while (true) { + ZipEntry entry = null; + + try { + entry = zip.getNextEntry(); + } catch ( java.io.IOException e ) { + // Todo: Error out. + return false; + } + + if ( entry == null ) { + break; + } + + Log.i("AssetExtract", "Extracting " + entry.getName()); + + if (entry.isDirectory()) { + + try { + new File(target +"/" + entry.getName()).mkdirs(); + } catch ( SecurityException e ) { }; + + continue; + } + + OutputStream out = null; + + String path = target + "/" + entry.getName(); + + try { + out = new FileOutputStream( path ); + } catch ( FileNotFoundException e ) { + } catch ( SecurityException e ) { }; + if ( out == null ) { + // TODO: Error. + return false; + } + + try { + while (true) { + int len = zip.read(buf); + + if (len == -1) { + break; + } + + out.write(buf, 0, len); + } + + out.flush(); + out.close(); + } catch ( java.io.IOException e ) { + // TODO: Deal w/ error. + return false; + } + } + + try { + zip.close(); + assetStream.close(); + } catch (IOException e) { + // pass + } + + return true; + } +}