Skip to content

Commit

Permalink
Merge pull request #79 from KennyMars/dev
Browse files Browse the repository at this point in the history
debug :zippy is closed
  • Loading branch information
singwhatiwanna committed Apr 3, 2015
2 parents 0405cfe + d5755db commit 144571b
Showing 1 changed file with 26 additions and 61 deletions.
87 changes: 26 additions & 61 deletions DynamicLoadApk/lib/src/com/ryg/utils/SoLibManager.java
Expand Up @@ -38,10 +38,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;

public final class SoLibManager {

private static final String TAG = SoLibManager.class.getSimpleName();
Expand Down Expand Up @@ -71,7 +67,7 @@ public static SoLibManager getSoLoader() {

/**
* get cpu name, according cpu type parse relevant so lib
*
*
* @return ARM、ARMV7、X86、MIPS
*/
private String getCpuName() {
Expand Down Expand Up @@ -109,11 +105,9 @@ private String getCpuArch(String cpuName) {

/**
* copy so lib to specify directory(/data/data/host_pack_name/pluginlib)
*
* @param dexPath
* plugin path
* @param cpuName
* cpuName CPU_X86,CPU_MIPS,CPU_ARMEABI
*
* @param dexPath plugin path
* @param nativeLibDir nativeLibDir
*/
public void copyPluginSoLib(Context context, String dexPath, String nativeLibDir) {
String cpuName = getCpuName();
Expand Down Expand Up @@ -172,70 +166,35 @@ private final String parseSoFileName(String zipEntryName) {
return zipEntryName.substring(zipEntryName.lastIndexOf("/") + 1);
}

private void writeSoFile2LibDir() {
private void writeSoFile2LibDir() throws IOException {
InputStream is = null;
FileOutputStream fos = null;
try {
is = mZipFile.getInputStream(mZipEntry);
fos = new FileOutputStream(new File(sNativeLibDir, mSoFileName));
} catch (IOException e) {
e.printStackTrace();
}
is = mZipFile.getInputStream(mZipEntry);
fos = new FileOutputStream(new File(sNativeLibDir, mSoFileName));
copy(is, fos);
try {
mZipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
mZipFile.close();
}

/**
* 输入输出流拷贝
*
*
* @param is
* @param os
*/
public void copy(InputStream is, OutputStream os) {
public void copy(InputStream is, OutputStream os) throws IOException {
if (is == null || os == null)
return;
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(os);
byte[] buf = null;
try {
buf = new byte[getAvailableSize(bis)];
} catch (IOException e) {
e.printStackTrace();
}
int size = getAvailableSize(bis);
byte[] buf = new byte[size];
int i = 0;
try {
while ((i = bis.read(buf)) != -1) {
bos.write(buf, 0, i);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
bos.flush();
bos.close();
bis.close();
} catch (IOException e) {
e.printStackTrace();
while ((i = bis.read(buf, 0, size)) != -1) {
bos.write(buf, 0, i);
}
// finally {
// try {
// bos.flush();
// } catch (IOException e) {
// }
// try {
// bos.close();
// } catch (IOException e) {
// }
//
// try {
// bis.close();
// } catch(IOException e) {
// }
// }
bos.flush();
bos.close();
bis.close();
}

private int getAvailableSize(InputStream is) throws IOException {
Expand All @@ -247,9 +206,15 @@ private int getAvailableSize(InputStream is) throws IOException {

@Override
public void run() {
writeSoFile2LibDir();
DLConfigs.setSoLastModifiedTime(mContext, mZipEntry.getName(), mLastModityTime);
Log.d(TAG, "copy so lib success: " + mZipEntry.getName());
try {
writeSoFile2LibDir();
DLConfigs.setSoLastModifiedTime(mContext, mZipEntry.getName(), mLastModityTime);
Log.d(TAG, "copy so lib success: " + mZipEntry.getName());
} catch (IOException e) {
Log.e(TAG, "copy so lib failed: " + e.toString());
e.printStackTrace();
}

}

}
Expand Down

0 comments on commit 144571b

Please sign in to comment.