Commit 2af06a4e by LAPTOP-146U5DF5\28422

增加了读取APK包数据大小的限制,如果超过1G就抛出异常

parent a226d4c2
......@@ -4,7 +4,7 @@ import android.util.Log;
public class MyLog {
private static final String TAG = "MyTest";
public static boolean is_Open=false;
public static boolean is_Open=true;
public static void d(Object object){
if(is_Open){
synchronized (object){
......
......@@ -218,33 +218,43 @@ public class NetWorkUtils {
byte[] data = new byte[8192];
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
int len = 0;
long obj=1024*1024*1024L;
long sum=0;
while((len = is.read(data)) != -1){
os.write(data,0,len);
sum+=len;
if(sum>obj){
MyLog.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!! 读取的数据大于1G 放弃");
throw new Exception("123123");
}
// ++num;
}
MyLog.d("!!!!!!!!!!!!!!!!!!!!!!!!!!!! 读取的文件大小:"+sum);
os.flush();
byte[] resData = null;
if(os instanceof ByteArrayOutputStream) {
resData = ((ByteArrayOutputStream)os).toByteArray();
}
String fileName = urlStr.split("https://adfly-facebook-1258892624.cos.ap-hongkong.myqcloud.com/apks/")[1].split(".apk")[0];
MyLog.d("获取的文件名:"+fileName);
String fileName = urlStr.split("https://adfly-facebook-1258892624.cos.ap-hongkong.myqcloud.com/apks/")[1];
MyLog.d("获取的文件名1:"+fileName);
fileName=fileName.substring(0,fileName.length()-4);
MyLog.d("获取的文件名2:"+fileName);
res = new Response(huc.getResponseCode(),huc.getResponseMessage(),resData,fileName);
os.close();
is.close();
huc.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (Exception e) {
MyLog.error(e.toString());
}
if(os!=null){
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
MyLog.d("发包结束:"+urlStr);
return res;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment