38
38
import java .util .zip .ZipEntry ;
39
39
import java .util .zip .ZipFile ;
40
40
41
- import android .annotation .SuppressLint ;
42
- import android .content .Context ;
43
- import android .util .Log ;
44
-
45
41
public final class SoLibManager {
46
42
47
43
private static final String TAG = SoLibManager .class .getSimpleName ();
@@ -71,7 +67,7 @@ public static SoLibManager getSoLoader() {
71
67
72
68
/**
73
69
* get cpu name, according cpu type parse relevant so lib
74
- *
70
+ *
75
71
* @return ARM、ARMV7、X86、MIPS
76
72
*/
77
73
private String getCpuName () {
@@ -109,11 +105,9 @@ private String getCpuArch(String cpuName) {
109
105
110
106
/**
111
107
* 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
117
111
*/
118
112
public void copyPluginSoLib (Context context , String dexPath , String nativeLibDir ) {
119
113
String cpuName = getCpuName ();
@@ -172,70 +166,35 @@ private final String parseSoFileName(String zipEntryName) {
172
166
return zipEntryName .substring (zipEntryName .lastIndexOf ("/" ) + 1 );
173
167
}
174
168
175
- private void writeSoFile2LibDir () {
169
+ private void writeSoFile2LibDir () throws IOException {
176
170
InputStream is = null ;
177
171
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 ));
184
174
copy (is , fos );
185
- try {
186
- mZipFile .close ();
187
- } catch (IOException e ) {
188
- e .printStackTrace ();
189
- }
175
+ mZipFile .close ();
190
176
}
191
177
192
178
/**
193
179
* 输入输出流拷贝
194
- *
180
+ *
195
181
* @param is
196
182
* @param os
197
183
*/
198
- public void copy (InputStream is , OutputStream os ) {
184
+ public void copy (InputStream is , OutputStream os ) throws IOException {
199
185
if (is == null || os == null )
200
186
return ;
201
187
BufferedInputStream bis = new BufferedInputStream (is );
202
188
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 ];
209
191
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 );
223
194
}
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 ();
239
198
}
240
199
241
200
private int getAvailableSize (InputStream is ) throws IOException {
@@ -247,9 +206,15 @@ private int getAvailableSize(InputStream is) throws IOException {
247
206
248
207
@ Override
249
208
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
+
253
218
}
254
219
255
220
}
0 commit comments