Skip to content

Commit 02d6228

Browse files
author
JemyCheung
committed
v7.6.2
1 parent fc0377c commit 02d6228

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

library/src/main/java/com/qiniu/android/http/DnsPrefetcher.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,12 @@ public static void startPrefetchDns(String token, Configuration config) {
415415
* @return
416416
*/
417417
public static boolean recoverDnsCache(byte[] data) {
418-
ConcurrentHashMap<String, List<InetAddress>> concurrentHashMap = (ConcurrentHashMap<String, List<InetAddress>>) StringUtils.toObject(data);
418+
ConcurrentHashMap<String, List<InetAddress>> concurrentHashMap = null;
419+
try {
420+
concurrentHashMap = (ConcurrentHashMap<String, List<InetAddress>>) StringUtils.toObject(data);
421+
}catch (Exception e){
422+
return true;
423+
}
419424
if (concurrentHashMap == null) {
420425
return true;
421426
}

library/src/main/java/com/qiniu/android/utils/StringUtils.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,21 @@ public static String strip(String s) {
147147
*/
148148
public static byte[] toByteArray(Object obj) {
149149
byte[] bytes = null;
150-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
151150
try {
152-
ObjectOutputStream oos = new ObjectOutputStream(bos);
153-
oos.writeObject(obj);
154-
oos.flush();
155-
bytes = bos.toByteArray();
156-
oos.close();
157-
bos.close();
158-
} catch (Exception ex) {
151+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
152+
try {
153+
ObjectOutputStream oos = new ObjectOutputStream(bos);
154+
try {
155+
oos.writeObject(obj);
156+
oos.flush();
157+
bytes = bos.toByteArray();
158+
} finally {
159+
oos.close();
160+
}
161+
} finally {
162+
bos.close();
163+
}
164+
} catch (IOException ex) {
159165
ex.printStackTrace();
160166
}
161167
return bytes;
@@ -171,14 +177,17 @@ public static Object toObject(byte[] bytes) {
171177
Object obj = null;
172178
try {
173179
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
174-
ObjectInputStream ois = new ObjectInputStream(bis);
175-
obj = ois.readObject();
176-
ois.close();
177-
bis.close();
178-
} catch (IOException ex) {
179-
ex.printStackTrace();
180-
} catch (ClassNotFoundException ex) {
181-
ex.printStackTrace();
180+
try {
181+
ObjectInputStream ois = new ObjectInputStream(bis);
182+
obj = ois.readObject();
183+
ois.close();
184+
} catch (Exception ex) {
185+
ex.printStackTrace();
186+
} finally {
187+
bis.close();
188+
}
189+
} catch (Exception e) {
190+
e.printStackTrace();
182191
}
183192
return obj;
184193
}

0 commit comments

Comments
 (0)