Skip to content

Commit 144571b

Browse files
Merge pull request #79 from KennyMars/dev
debug :zippy is closed
2 parents 0405cfe + d5755db commit 144571b

File tree

1 file changed

+26
-61
lines changed

1 file changed

+26
-61
lines changed

DynamicLoadApk/lib/src/com/ryg/utils/SoLibManager.java

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
import java.util.zip.ZipEntry;
3939
import java.util.zip.ZipFile;
4040

41-
import android.annotation.SuppressLint;
42-
import android.content.Context;
43-
import android.util.Log;
44-
4541
public final class SoLibManager {
4642

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

7268
/**
7369
* get cpu name, according cpu type parse relevant so lib
74-
*
70+
*
7571
* @return ARM、ARMV7、X86、MIPS
7672
*/
7773
private String getCpuName() {
@@ -109,11 +105,9 @@ private String getCpuArch(String cpuName) {
109105

110106
/**
111107
* copy so lib to specify directory(/data/data/host_pack_name/pluginlib)
112-
*
113-
* @param dexPath
114-
* plugin path
115-
* @param cpuName
116-
* cpuName CPU_X86,CPU_MIPS,CPU_ARMEABI
108+
*
109+
* @param dexPath plugin path
110+
* @param nativeLibDir nativeLibDir
117111
*/
118112
public void copyPluginSoLib(Context context, String dexPath, String nativeLibDir) {
119113
String cpuName = getCpuName();
@@ -172,70 +166,35 @@ private final String parseSoFileName(String zipEntryName) {
172166
return zipEntryName.substring(zipEntryName.lastIndexOf("/") + 1);
173167
}
174168

175-
private void writeSoFile2LibDir() {
169+
private void writeSoFile2LibDir() throws IOException {
176170
InputStream is = null;
177171
FileOutputStream fos = null;
178-
try {
179-
is = mZipFile.getInputStream(mZipEntry);
180-
fos = new FileOutputStream(new File(sNativeLibDir, mSoFileName));
181-
} catch (IOException e) {
182-
e.printStackTrace();
183-
}
172+
is = mZipFile.getInputStream(mZipEntry);
173+
fos = new FileOutputStream(new File(sNativeLibDir, mSoFileName));
184174
copy(is, fos);
185-
try {
186-
mZipFile.close();
187-
} catch (IOException e) {
188-
e.printStackTrace();
189-
}
175+
mZipFile.close();
190176
}
191177

192178
/**
193179
* 输入输出流拷贝
194-
*
180+
*
195181
* @param is
196182
* @param os
197183
*/
198-
public void copy(InputStream is, OutputStream os) {
184+
public void copy(InputStream is, OutputStream os) throws IOException {
199185
if (is == null || os == null)
200186
return;
201187
BufferedInputStream bis = new BufferedInputStream(is);
202188
BufferedOutputStream bos = new BufferedOutputStream(os);
203-
byte[] buf = null;
204-
try {
205-
buf = new byte[getAvailableSize(bis)];
206-
} catch (IOException e) {
207-
e.printStackTrace();
208-
}
189+
int size = getAvailableSize(bis);
190+
byte[] buf = new byte[size];
209191
int i = 0;
210-
try {
211-
while ((i = bis.read(buf)) != -1) {
212-
bos.write(buf, 0, i);
213-
}
214-
} catch (IOException e) {
215-
e.printStackTrace();
216-
}
217-
try {
218-
bos.flush();
219-
bos.close();
220-
bis.close();
221-
} catch (IOException e) {
222-
e.printStackTrace();
192+
while ((i = bis.read(buf, 0, size)) != -1) {
193+
bos.write(buf, 0, i);
223194
}
224-
// finally {
225-
// try {
226-
// bos.flush();
227-
// } catch (IOException e) {
228-
// }
229-
// try {
230-
// bos.close();
231-
// } catch (IOException e) {
232-
// }
233-
//
234-
// try {
235-
// bis.close();
236-
// } catch(IOException e) {
237-
// }
238-
// }
195+
bos.flush();
196+
bos.close();
197+
bis.close();
239198
}
240199

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

248207
@Override
249208
public void run() {
250-
writeSoFile2LibDir();
251-
DLConfigs.setSoLastModifiedTime(mContext, mZipEntry.getName(), mLastModityTime);
252-
Log.d(TAG, "copy so lib success: " + mZipEntry.getName());
209+
try {
210+
writeSoFile2LibDir();
211+
DLConfigs.setSoLastModifiedTime(mContext, mZipEntry.getName(), mLastModityTime);
212+
Log.d(TAG, "copy so lib success: " + mZipEntry.getName());
213+
} catch (IOException e) {
214+
Log.e(TAG, "copy so lib failed: " + e.toString());
215+
e.printStackTrace();
216+
}
217+
253218
}
254219

255220
}

0 commit comments

Comments
 (0)