entity结构修改前备份
This commit is contained in:
@ -33,7 +33,7 @@ import com.arialyy.aria.core.inf.ICmd;
|
|||||||
import com.arialyy.aria.core.inf.IReceiver;
|
import com.arialyy.aria.core.inf.IReceiver;
|
||||||
import com.arialyy.aria.core.upload.UploadReceiver;
|
import com.arialyy.aria.core.upload.UploadReceiver;
|
||||||
import com.arialyy.aria.orm.DbUtil;
|
import com.arialyy.aria.orm.DbUtil;
|
||||||
import com.arialyy.aria.util.FileUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -251,8 +251,8 @@ import org.xml.sax.SAXException;
|
|||||||
loadConfig();
|
loadConfig();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
String md5Code = FileUtil.getFileMD5(xmlFile);
|
String md5Code = CommonUtil.getFileMD5(xmlFile);
|
||||||
if (!FileUtil.checkMD5(md5Code, APP.getAssets().open("aria_config.xml"))) {
|
if (!CommonUtil.checkMD5(md5Code, APP.getAssets().open("aria_config.xml"))) {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -17,7 +17,6 @@ package com.arialyy.aria.core;
|
|||||||
|
|
||||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import com.arialyy.aria.util.ReflectionUtil;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@ -155,7 +154,7 @@ class Configuration {
|
|||||||
: UPLOAD_CONFIG_FILE));
|
: UPLOAD_CONFIG_FILE));
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
Properties properties = CommonUtil.loadConfig(file);
|
Properties properties = CommonUtil.loadConfig(file);
|
||||||
List<Field> fields = ReflectionUtil.getAllFields(getClass());
|
List<Field> fields = CommonUtil.getAllFields(getClass());
|
||||||
try {
|
try {
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
int m = field.getModifiers();
|
int m = field.getModifiers();
|
||||||
@ -189,7 +188,7 @@ class Configuration {
|
|||||||
* 保存配置
|
* 保存配置
|
||||||
*/
|
*/
|
||||||
void saveAll() {
|
void saveAll() {
|
||||||
List<Field> fields = ReflectionUtil.getAllFields(getClass());
|
List<Field> fields = CommonUtil.getAllFields(getClass());
|
||||||
boolean isDownload = this instanceof DownloadConfig;
|
boolean isDownload = this instanceof DownloadConfig;
|
||||||
try {
|
try {
|
||||||
File file = new File(
|
File file = new File(
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.arialyy.aria.core.download;
|
package com.arialyy.aria.core.download;
|
||||||
|
|
||||||
import com.arialyy.aria.util.CAConfiguration;
|
|
||||||
import com.arialyy.aria.util.SSLContextUtil;
|
import com.arialyy.aria.util.SSLContextUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@ -43,7 +42,7 @@ class ConnectionHelp {
|
|||||||
if (urlConn instanceof HttpsURLConnection) {
|
if (urlConn instanceof HttpsURLConnection) {
|
||||||
conn = (HttpsURLConnection) urlConn;
|
conn = (HttpsURLConnection) urlConn;
|
||||||
SSLContext sslContext =
|
SSLContext sslContext =
|
||||||
SSLContextUtil.getSSLContext(CAConfiguration.CA_ALIAS, CAConfiguration.CA_PATH);
|
SSLContextUtil.getSSLContext(SSLContextUtil.CA_ALIAS, SSLContextUtil.CA_PATH);
|
||||||
if (sslContext == null) {
|
if (sslContext == null) {
|
||||||
sslContext = SSLContextUtil.getDefaultSLLContext();
|
sslContext = SSLContextUtil.getDefaultSLLContext();
|
||||||
}
|
}
|
||||||
@ -75,8 +74,6 @@ class ConnectionHelp {
|
|||||||
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
|
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
|
||||||
conn.setRequestProperty("Accept",
|
conn.setRequestProperty("Accept",
|
||||||
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
|
"image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
|
||||||
////用于处理Disconnect 不起作用问题
|
|
||||||
//conn.setRequestProperty("Connection", "close");
|
|
||||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||||
//302获取重定向地址
|
//302获取重定向地址
|
||||||
conn.setInstanceFollowRedirects(false);
|
conn.setInstanceFollowRedirects(false);
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package com.arialyy.aria.core.inf;
|
||||||
|
|
||||||
package com.arialyy.aria.util;
|
import com.arialyy.aria.orm.DbEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2017/1/11.
|
* Created by AriaL on 2017/6/3.
|
||||||
*/
|
*/
|
||||||
|
public abstract class AbsEntity extends DbEntity implements IEntity {
|
||||||
|
|
||||||
public class CAConfiguration {
|
|
||||||
public static String CA_PATH, CA_ALIAS;
|
|
||||||
}
|
}
|
@ -97,7 +97,6 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
for (String tableName : tables) {
|
for (String tableName : tables) {
|
||||||
Class clazz = DBConfig.mapping.get(tableName);
|
Class clazz = DBConfig.mapping.get(tableName);
|
||||||
if (tableExists(db, clazz)) {
|
if (tableExists(db, clazz)) {
|
||||||
//db = checkDb(db);
|
|
||||||
String countColumnSql = "SELECT rowid FROM " + tableName;
|
String countColumnSql = "SELECT rowid FROM " + tableName;
|
||||||
Cursor cursor = db.rawQuery(countColumnSql, null);
|
Cursor cursor = db.rawQuery(countColumnSql, null);
|
||||||
int dbColumnNum = cursor.getColumnCount();
|
int dbColumnNum = cursor.getColumnCount();
|
||||||
@ -370,8 +369,10 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
*/
|
*/
|
||||||
static synchronized void createTable(SQLiteDatabase db, Class clazz, String tableName) {
|
static synchronized void createTable(SQLiteDatabase db, Class clazz, String tableName) {
|
||||||
db = checkDb(db);
|
db = checkDb(db);
|
||||||
Field[] fields = CommonUtil.getFields(clazz);
|
//Field[] fields = CommonUtil.getFields(clazz);
|
||||||
if (fields != null && fields.length > 0) {
|
List<Field> fields = CommonUtil.getAllFields(clazz);
|
||||||
|
//Field[] fields = CommonUtil.getAllFields(clazz);
|
||||||
|
if (fields != null && fields.size() > 0) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("create table ")
|
sb.append("create table ")
|
||||||
.append(TextUtils.isEmpty(tableName) ? CommonUtil.getClassName(clazz) : tableName)
|
.append(TextUtils.isEmpty(tableName) ? CommonUtil.getClassName(clazz) : tableName)
|
||||||
@ -486,7 +487,6 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
|
entity.rowID = cursor.getInt(cursor.getColumnIndex("rowid"));
|
||||||
entitys.add(entity);
|
entitys.add(entity);
|
||||||
//Log.d(TAG, "rowid ==> " + entity.rowID);
|
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
@ -515,7 +515,11 @@ final class SqlHelper extends SQLiteOpenHelper {
|
|||||||
static boolean ignoreField(Field field) {
|
static boolean ignoreField(Field field) {
|
||||||
// field.isSynthetic(), 使用as热启动App时,AS会自动给你的clss添加change字段
|
// field.isSynthetic(), 使用as热启动App时,AS会自动给你的clss添加change字段
|
||||||
Ignore ignore = field.getAnnotation(Ignore.class);
|
Ignore ignore = field.getAnnotation(Ignore.class);
|
||||||
return (ignore != null && ignore.value()) || field.isSynthetic() || Modifier.isStatic(
|
int modifiers = field.getModifiers();
|
||||||
field.getModifiers()) || Modifier.isFinal(field.getModifiers());
|
return (ignore != null && ignore.value())
|
||||||
|
|| field.getName().equals("rowID")
|
||||||
|
|| field.isSynthetic()
|
||||||
|
|| Modifier.isStatic(modifiers)
|
||||||
|
|| Modifier.isFinal(modifiers);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,8 +24,6 @@ import java.io.IOException;
|
|||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
//import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <code>BufferedRandomAccessFile</code> is like a
|
* A <code>BufferedRandomAccessFile</code> is like a
|
||||||
* <code>RandomAccessFile</code>, but it uses a private buffer so that most
|
* <code>RandomAccessFile</code>, but it uses a private buffer so that most
|
||||||
|
@ -20,25 +20,134 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.arialyy.aria.core.command.CmdFactory;
|
import com.arialyy.aria.core.command.CmdFactory;
|
||||||
import com.arialyy.aria.core.command.AbsCmd;
|
import com.arialyy.aria.core.command.AbsCmd;
|
||||||
import com.arialyy.aria.core.inf.ITaskEntity;
|
import com.arialyy.aria.core.inf.ITaskEntity;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyy on 2016/1/22.
|
* Created by lyy on 2016/1/22.
|
||||||
*/
|
*/
|
||||||
public class CommonUtil {
|
public class CommonUtil {
|
||||||
private static final String TAG = "util";
|
private static final String TAG = "CommonUtil";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过流创建文件
|
||||||
|
*/
|
||||||
|
public static void createFileFormInputStream(InputStream is, String path) {
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(path);
|
||||||
|
byte[] buf = new byte[1376];
|
||||||
|
while (is.read(buf) > 0) {
|
||||||
|
fos.write(buf, 0, buf.length);
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
fos.flush();
|
||||||
|
fos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验文件MD5码
|
||||||
|
*/
|
||||||
|
public static boolean checkMD5(String md5, File updateFile) {
|
||||||
|
if (TextUtils.isEmpty(md5) || updateFile == null) {
|
||||||
|
Log.e(TAG, "MD5 string empty or updateFile null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String calculatedDigest = getFileMD5(updateFile);
|
||||||
|
if (calculatedDigest == null) {
|
||||||
|
Log.e(TAG, "calculatedDigest null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return calculatedDigest.equalsIgnoreCase(md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验文件MD5码
|
||||||
|
*/
|
||||||
|
public static boolean checkMD5(String md5, InputStream is) {
|
||||||
|
if (TextUtils.isEmpty(md5) || is == null) {
|
||||||
|
Log.e(TAG, "MD5 string empty or updateFile null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String calculatedDigest = getFileMD5(is);
|
||||||
|
if (calculatedDigest == null) {
|
||||||
|
Log.e(TAG, "calculatedDigest null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return calculatedDigest.equalsIgnoreCase(md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件MD5码
|
||||||
|
*/
|
||||||
|
public static String getFileMD5(File updateFile) {
|
||||||
|
InputStream is;
|
||||||
|
try {
|
||||||
|
is = new FileInputStream(updateFile);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
Log.e(TAG, "Exception while getting FileInputStream", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getFileMD5(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件MD5码
|
||||||
|
*/
|
||||||
|
public static String getFileMD5(InputStream is) {
|
||||||
|
MessageDigest digest;
|
||||||
|
try {
|
||||||
|
digest = MessageDigest.getInstance("MD5");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
Log.e(TAG, "Exception while getting digest", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
int read;
|
||||||
|
try {
|
||||||
|
while ((read = is.read(buffer)) > 0) {
|
||||||
|
digest.update(buffer, 0, read);
|
||||||
|
}
|
||||||
|
byte[] md5sum = digest.digest();
|
||||||
|
BigInteger bigInt = new BigInteger(1, md5sum);
|
||||||
|
String output = bigInt.toString(16);
|
||||||
|
// Fill to 32 chars
|
||||||
|
output = String.format("%32s", output).replace(' ', '0');
|
||||||
|
return output;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Unable to process file for MD5", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "Exception on closing MD5 input stream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends ITaskEntity> AbsCmd createCmd(String target, T entity, int cmd) {
|
public static <T extends ITaskEntity> AbsCmd createCmd(String target, T entity, int cmd) {
|
||||||
return CmdFactory.getInstance().createCmd(target, entity, cmd);
|
return CmdFactory.getInstance().createCmd(target, entity, cmd);
|
||||||
@ -83,6 +192,19 @@ public class CommonUtil {
|
|||||||
return pre.getString(key, "");
|
return pre.getString(key, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有字段,包括父类的字段
|
||||||
|
*/
|
||||||
|
public static List<Field> getAllFields(Class clazz) {
|
||||||
|
List<Field> fields = new ArrayList<>();
|
||||||
|
Class personClazz = clazz.getSuperclass();
|
||||||
|
if (personClazz != null) {
|
||||||
|
Collections.addAll(fields, personClazz.getDeclaredFields());
|
||||||
|
}
|
||||||
|
Collections.addAll(fields, clazz.getDeclaredFields());
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取类里面的所在字段
|
* 获取类里面的所在字段
|
||||||
*/
|
*/
|
||||||
|
@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.arialyy.aria.util;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyy on 2017/3/21.
|
|
||||||
*/
|
|
||||||
public class FileUtil {
|
|
||||||
|
|
||||||
private static final String TAG = "FileUtil";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过流创建文件
|
|
||||||
*/
|
|
||||||
public static void createFileFormInputStream(InputStream is, String path) {
|
|
||||||
try {
|
|
||||||
FileOutputStream fos = new FileOutputStream(path);
|
|
||||||
byte[] buf = new byte[1376];
|
|
||||||
while (is.read(buf) > 0) {
|
|
||||||
fos.write(buf, 0, buf.length);
|
|
||||||
}
|
|
||||||
is.close();
|
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验文件MD5码
|
|
||||||
*/
|
|
||||||
public static boolean checkMD5(String md5, File updateFile) {
|
|
||||||
if (TextUtils.isEmpty(md5) || updateFile == null) {
|
|
||||||
Log.e(TAG, "MD5 string empty or updateFile null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String calculatedDigest = getFileMD5(updateFile);
|
|
||||||
if (calculatedDigest == null) {
|
|
||||||
Log.e(TAG, "calculatedDigest null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return calculatedDigest.equalsIgnoreCase(md5);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验文件MD5码
|
|
||||||
*/
|
|
||||||
public static boolean checkMD5(String md5, InputStream is) {
|
|
||||||
if (TextUtils.isEmpty(md5) || is == null) {
|
|
||||||
Log.e(TAG, "MD5 string empty or updateFile null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String calculatedDigest = getFileMD5(is);
|
|
||||||
if (calculatedDigest == null) {
|
|
||||||
Log.e(TAG, "calculatedDigest null");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return calculatedDigest.equalsIgnoreCase(md5);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件MD5码
|
|
||||||
*/
|
|
||||||
public static String getFileMD5(File updateFile) {
|
|
||||||
InputStream is;
|
|
||||||
try {
|
|
||||||
is = new FileInputStream(updateFile);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
Log.e(TAG, "Exception while getting FileInputStream", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return getFileMD5(is);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件MD5码
|
|
||||||
*/
|
|
||||||
public static String getFileMD5(InputStream is) {
|
|
||||||
MessageDigest digest;
|
|
||||||
try {
|
|
||||||
digest = MessageDigest.getInstance("MD5");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
Log.e(TAG, "Exception while getting digest", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
|
||||||
int read;
|
|
||||||
try {
|
|
||||||
while ((read = is.read(buffer)) > 0) {
|
|
||||||
digest.update(buffer, 0, read);
|
|
||||||
}
|
|
||||||
byte[] md5sum = digest.digest();
|
|
||||||
BigInteger bigInt = new BigInteger(1, md5sum);
|
|
||||||
String output = bigInt.toString(16);
|
|
||||||
// Fill to 32 chars
|
|
||||||
output = String.format("%32s", output).replace(' ', '0');
|
|
||||||
return output;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Unable to process file for MD5", e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
is.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Exception on closing MD5 input stream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.arialyy.aria.util;
|
|
||||||
|
|
||||||
import android.os.Environment;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyy on 2016/9/27.
|
|
||||||
* 下载路径帮助类
|
|
||||||
*/
|
|
||||||
public class PathUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载链接转换保存路径
|
|
||||||
*
|
|
||||||
* @param downloadUrl 下载链接
|
|
||||||
* @return 保存路径
|
|
||||||
*/
|
|
||||||
public static String urlconvertPath(String downloadUrl) {
|
|
||||||
return Environment.getDownloadCacheDirectory().getPath() + "/" + StringToHashKey(downloadUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字符串转换为hash码
|
|
||||||
*/
|
|
||||||
public static String StringToHashKey(String str) {
|
|
||||||
String cacheKey;
|
|
||||||
try {
|
|
||||||
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
|
|
||||||
mDigest.update(str.getBytes());
|
|
||||||
cacheKey = bytesToHexString(mDigest.digest());
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
cacheKey = String.valueOf(str.hashCode());
|
|
||||||
}
|
|
||||||
return cacheKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将普通字符串转换为16位进制字符串
|
|
||||||
*/
|
|
||||||
public static String bytesToHexString(byte[] src) {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder("0x");
|
|
||||||
if (src == null || src.length <= 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
char[] buffer = new char[2];
|
|
||||||
for (byte aSrc : src) {
|
|
||||||
buffer[0] = Character.forDigit((aSrc >>> 4) & 0x0F, 16);
|
|
||||||
buffer[1] = Character.forDigit(aSrc & 0x0F, 16);
|
|
||||||
stringBuilder.append(buffer);
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.arialyy.aria.util;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyy on 2015/7/30.
|
|
||||||
* 反射工具类
|
|
||||||
*/
|
|
||||||
public class ReflectionUtil {
|
|
||||||
private static final String TAG = "ReflectionUtil";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取类里面的所在字段
|
|
||||||
*/
|
|
||||||
public static Field[] getFields(Class clazz) {
|
|
||||||
Field[] fields = null;
|
|
||||||
fields = clazz.getDeclaredFields();
|
|
||||||
if (fields == null || fields.length == 0) {
|
|
||||||
Class superClazz = clazz.getSuperclass();
|
|
||||||
if (superClazz != null) {
|
|
||||||
fields = getFields(superClazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有字段,包括父类的字段
|
|
||||||
*/
|
|
||||||
public static List<Field> getAllFields(Class clazz) {
|
|
||||||
List<Field> fields = new ArrayList<>();
|
|
||||||
Class personClazz = clazz.getSuperclass();
|
|
||||||
if (personClazz != null) {
|
|
||||||
Collections.addAll(fields, personClazz.getDeclaredFields());
|
|
||||||
}
|
|
||||||
Collections.addAll(fields, clazz.getDeclaredFields());
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取类里面的指定对象,如果该类没有则从父类查询
|
|
||||||
*/
|
|
||||||
public static Field getField(Class clazz, String name) {
|
|
||||||
Field field = null;
|
|
||||||
try {
|
|
||||||
field = clazz.getDeclaredField(name);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
try {
|
|
||||||
field = clazz.getField(name);
|
|
||||||
} catch (NoSuchFieldException e1) {
|
|
||||||
if (clazz.getSuperclass() == null) {
|
|
||||||
return field;
|
|
||||||
} else {
|
|
||||||
field = getField(clazz.getSuperclass(), name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (field != null) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
}
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 利用递归找一个类的指定方法,如果找不到,去父亲里面找直到最上层Object对象为止。
|
|
||||||
*
|
|
||||||
* @param clazz 目标类
|
|
||||||
* @param methodName 方法名
|
|
||||||
* @param params 方法参数类型数组
|
|
||||||
* @return 方法对象
|
|
||||||
*/
|
|
||||||
public static Method getMethod(Class clazz, String methodName, final Class<?>... params) {
|
|
||||||
Method method = null;
|
|
||||||
try {
|
|
||||||
method = clazz.getDeclaredMethod(methodName, params);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
try {
|
|
||||||
method = clazz.getMethod(methodName, params);
|
|
||||||
} catch (NoSuchMethodException ex) {
|
|
||||||
if (clazz.getSuperclass() == null) {
|
|
||||||
Log.e(TAG, "无法找到" + methodName + "方法");
|
|
||||||
return method;
|
|
||||||
} else {
|
|
||||||
method = getMethod(clazz.getSuperclass(), methodName, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (method != null) {
|
|
||||||
method.setAccessible(true);
|
|
||||||
}
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
}
|
|
@ -43,6 +43,8 @@ import javax.net.ssl.X509TrustManager;
|
|||||||
*/
|
*/
|
||||||
public class SSLContextUtil {
|
public class SSLContextUtil {
|
||||||
|
|
||||||
|
public static String CA_PATH, CA_ALIAS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 颁发服务器证书的 CA 未知
|
* 颁发服务器证书的 CA 未知
|
||||||
*
|
*
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.arialyy.aria.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by lyy on 2017/3/6.
|
|
||||||
*/
|
|
||||||
public enum Speed {
|
|
||||||
/**
|
|
||||||
* 最大速度为256kb
|
|
||||||
*/
|
|
||||||
KB_256(64), /**
|
|
||||||
* 最大速度为512kb
|
|
||||||
*/
|
|
||||||
KB_512(128), /**
|
|
||||||
* 最大速度为1mb
|
|
||||||
*/
|
|
||||||
MB_1(256), /**
|
|
||||||
* 最大速度为2mb
|
|
||||||
*/
|
|
||||||
MB_2(1024), /**
|
|
||||||
* 最大速度为10mb
|
|
||||||
*/
|
|
||||||
MAX(8192);
|
|
||||||
int buf;
|
|
||||||
|
|
||||||
Speed(int buf) {
|
|
||||||
this.buf = buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package com.arialyy.simple.common;
|
package com.arialyy.simple.common;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
package com.arialyy.simple.download;
|
package com.arialyy.simple.download;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -5,7 +20,6 @@ import android.os.Environment;
|
|||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
@ -39,12 +39,10 @@ import com.arialyy.aria.core.download.DownloadEntity;
|
|||||||
import com.arialyy.aria.core.download.DownloadTask;
|
import com.arialyy.aria.core.download.DownloadTask;
|
||||||
import com.arialyy.aria.core.inf.IEntity;
|
import com.arialyy.aria.core.inf.IEntity;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import com.arialyy.aria.util.Speed;
|
|
||||||
import com.arialyy.frame.util.show.L;
|
import com.arialyy.frame.util.show.L;
|
||||||
import com.arialyy.frame.util.show.T;
|
import com.arialyy.frame.util.show.T;
|
||||||
import com.arialyy.simple.R;
|
import com.arialyy.simple.R;
|
||||||
import com.arialyy.simple.base.BaseActivity;
|
import com.arialyy.simple.base.BaseActivity;
|
||||||
import com.arialyy.simple.common.MsgDialog;
|
|
||||||
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
||||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user