parent
							
								
									30c41e4cb2
								
							
						
					
					
						commit
						b3501dc3c3
					
				| @ -1,70 +1,70 @@ | ||||
| /* | ||||
|  * 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.core.common.ftp; | ||||
| 
 | ||||
| import android.text.TextUtils; | ||||
| import com.arialyy.aria.core.FtpUrlEntity; | ||||
| import com.arialyy.aria.core.inf.AbsTarget; | ||||
| import com.arialyy.aria.core.inf.IFtpTarget; | ||||
| import com.arialyy.aria.util.ALog; | ||||
| import java.net.Proxy; | ||||
| 
 | ||||
| /** | ||||
|  * Created by laoyuyu on 2018/3/9. | ||||
|  * ftp 委托 | ||||
|  */ | ||||
| public class FtpDelegate<TARGET extends AbsTarget> implements IFtpTarget<TARGET> { | ||||
|   private static final String TAG = "FtpDelegate"; | ||||
|   private FtpUrlEntity mUrlEntity; | ||||
|   private TARGET mTarget; | ||||
| 
 | ||||
|   public FtpDelegate(TARGET target) { | ||||
|     mTarget = target; | ||||
|     mUrlEntity = target.getTaskWrapper().asFtp().getUrlEntity(); | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET charSet(String charSet) { | ||||
|     if (TextUtils.isEmpty(charSet)) { | ||||
|       throw new NullPointerException("字符编码为空"); | ||||
|     } | ||||
|     mTarget.getTaskWrapper().asFtp().setCharSet(charSet); | ||||
|     return mTarget; | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET login(String userName, String password) { | ||||
|     return login(userName, password, null); | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET login(String userName, String password, String account) { | ||||
|     if (TextUtils.isEmpty(userName)) { | ||||
|       ALog.e(TAG, "用户名不能为null"); | ||||
|       return mTarget; | ||||
|     } else if (TextUtils.isEmpty(password)) { | ||||
|       ALog.e(TAG, "密码不能为null"); | ||||
|       return mTarget; | ||||
|     } | ||||
|     mUrlEntity.needLogin = true; | ||||
|     mUrlEntity.user = userName; | ||||
|     mUrlEntity.password = password; | ||||
|     mUrlEntity.account = account; | ||||
|     return mTarget; | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET setProxy(Proxy proxy) { | ||||
|     mTarget.getTaskWrapper().asFtp().setProxy(proxy); | ||||
|     return mTarget; | ||||
|   } | ||||
| } | ||||
| /* | ||||
|  * 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.core.common.ftp; | ||||
| 
 | ||||
| import android.text.TextUtils; | ||||
| import com.arialyy.aria.core.FtpUrlEntity; | ||||
| import com.arialyy.aria.core.inf.AbsTarget; | ||||
| import com.arialyy.aria.core.inf.IFtpTarget; | ||||
| import com.arialyy.aria.util.ALog; | ||||
| import java.net.Proxy; | ||||
| 
 | ||||
| /** | ||||
|  * Created by laoyuyu on 2018/3/9. | ||||
|  * ftp 委托 | ||||
|  */ | ||||
| public class FtpDelegate<TARGET extends AbsTarget> implements IFtpTarget<TARGET> { | ||||
|   private static final String TAG = "FtpDelegate"; | ||||
|   private TARGET mTarget; | ||||
| 
 | ||||
|   public FtpDelegate(TARGET target) { | ||||
|     mTarget = target; | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET charSet(String charSet) { | ||||
|     if (TextUtils.isEmpty(charSet)) { | ||||
|       throw new NullPointerException("字符编码为空"); | ||||
|     } | ||||
|     mTarget.getTaskWrapper().asFtp().setCharSet(charSet); | ||||
|     return mTarget; | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET login(String userName, String password) { | ||||
|     return login(userName, password, null); | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET login(String userName, String password, String account) { | ||||
|     if (TextUtils.isEmpty(userName)) { | ||||
|       ALog.e(TAG, "用户名不能为null"); | ||||
|       return mTarget; | ||||
|     } else if (TextUtils.isEmpty(password)) { | ||||
|       ALog.e(TAG, "密码不能为null"); | ||||
|       return mTarget; | ||||
|     } | ||||
|     // urlEntity 不能在构造函数中获取,因为ftp上传时url是后于构造函数的
 | ||||
|     FtpUrlEntity urlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); | ||||
|     urlEntity.needLogin = true; | ||||
|     urlEntity.user = userName; | ||||
|     urlEntity.password = password; | ||||
|     urlEntity.account = account; | ||||
|     return mTarget; | ||||
|   } | ||||
| 
 | ||||
|   @Override public TARGET setProxy(Proxy proxy) { | ||||
|     mTarget.getTaskWrapper().asFtp().setProxy(proxy); | ||||
|     return mTarget; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,199 +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.core.download;
 | ||||
| //
 | ||||
| //import android.text.TextUtils;
 | ||||
| //import com.arialyy.aria.core.manager.TaskWrapperManager;
 | ||||
| //import com.arialyy.aria.core.queue.DownloadTaskQueue;
 | ||||
| //import com.arialyy.aria.orm.DbEntity;
 | ||||
| //import com.arialyy.aria.util.ALog;
 | ||||
| //import com.arialyy.aria.util.CommonUtil;
 | ||||
| //import java.io.File;
 | ||||
| //
 | ||||
| ///**
 | ||||
| // * Created by Aria.Lao on 2017/7/26.
 | ||||
| // */
 | ||||
| //abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
 | ||||
| //    extends AbsDownloadTarget<TARGET, DownloadEntity, DTaskWrapper> {
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 通过地址初始化target
 | ||||
| //   */
 | ||||
| //  void initTarget(String url, String targetName) {
 | ||||
| //    setUrl(url);
 | ||||
| //    setTargetName(targetName);
 | ||||
| //    setTaskWrapper(TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, url));
 | ||||
| //    mEntity = getTaskWrapper().getEntity();
 | ||||
| //
 | ||||
| //    if (mEntity != null) {
 | ||||
| //      setTempFilePath(mEntity.getDownloadPath());
 | ||||
| //    }
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 更新下载url
 | ||||
| //   *
 | ||||
| //   * @param newUrl 新的下载url
 | ||||
| //   */
 | ||||
| //  public TARGET updateUrl(String newUrl) {
 | ||||
| //    if (TextUtils.isEmpty(newUrl)) {
 | ||||
| //      ALog.e(TAG, "下载url更新失败,newUrl为null");
 | ||||
| //      return (TARGET) this;
 | ||||
| //    }
 | ||||
| //    if (getUrl().equals(newUrl)) {
 | ||||
| //      ALog.e(TAG, "下载url更新失败,新的下载url和旧的url一致");
 | ||||
| //      return (TARGET) this;
 | ||||
| //    }
 | ||||
| //    setNewUrl(newUrl);
 | ||||
| //    getTaskWrapper().setRefreshInfo(true);
 | ||||
| //    return (TARGET) this;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 将任务设置为最高优先级任务,最高优先级任务有以下特点:
 | ||||
| //   * 1、在下载队列中,有且只有一个最高优先级任务
 | ||||
| //   * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成
 | ||||
| //   * 3、任务调度器不会暂停最高优先级任务
 | ||||
| //   * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效
 | ||||
| //   * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行
 | ||||
| //   * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务
 | ||||
| //   */
 | ||||
| //  @Override public void setHighestPriority() {
 | ||||
| //    super.setHighestPriority();
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 下载任务是否存在
 | ||||
| //   *
 | ||||
| //   * @return {@code true}任务存在
 | ||||
| //   */
 | ||||
| //  @Override public boolean taskExists() {
 | ||||
| //    return DbEntity.checkDataExist(DownloadEntity.class, "url=?", getUrl());
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 获取下载实体
 | ||||
| //   */
 | ||||
| //  public DownloadEntity getDownloadEntity() {
 | ||||
| //    return mEntity;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 是否在下载
 | ||||
| //   *
 | ||||
| //   * @return {@code true}任务正在下载
 | ||||
| //   */
 | ||||
| //  @Override public boolean isRunning() {
 | ||||
| //    DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity.getKey());
 | ||||
| //    return task != null && task.isRunning();
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 检查下载实体,判断实体是否合法 合法标准为:
 | ||||
| //   * 1、下载路径不为null,并且下载路径是正常的http或ftp路径
 | ||||
| //   * 2、保存路径不为null,并且保存路径是android文件系统路径
 | ||||
| //   * 3、保存路径不能重复
 | ||||
| //   *
 | ||||
| //   * @return {@code true}合法
 | ||||
| //   */
 | ||||
| //  @Override protected boolean checkEntity() {
 | ||||
| //    boolean b = getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath();
 | ||||
| //    if (b) {
 | ||||
| //      mEntity.save();
 | ||||
| //    }
 | ||||
| //    return b;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 检查并设置普通任务的文件保存路径
 | ||||
| //   *
 | ||||
| //   * @return {@code true}保存路径合法
 | ||||
| //   */
 | ||||
| //  private boolean checkFilePath() {
 | ||||
| //    String filePath = getTempFilePath();
 | ||||
| //    if (TextUtils.isEmpty(filePath)) {
 | ||||
| //      ALog.e(TAG, "下载失败,文件保存路径为null");
 | ||||
| //      return false;
 | ||||
| //    } else if (!filePath.startsWith("/")) {
 | ||||
| //      ALog.e(TAG, "下载失败,文件保存路径【" + filePath + "】错误");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    File file = new File(filePath);
 | ||||
| //    if (file.isDirectory()) {
 | ||||
| //      if (getTargetType() == HTTP) {
 | ||||
| //        ALog.e(TAG, "下载失败,保存路径【" + filePath + "】不能为文件夹,路径需要是完整的文件路径,如:/mnt/sdcard/game.zip");
 | ||||
| //        return false;
 | ||||
| //      } else if (getTargetType() == FTP) {
 | ||||
| //        filePath += mEntity.getFileName();
 | ||||
| //      }
 | ||||
| //    } else {
 | ||||
| //      // http文件名设置
 | ||||
| //      if (TextUtils.isEmpty(mEntity.getFileName())) {
 | ||||
| //        mEntity.setFileName(file.getName());
 | ||||
| //      }
 | ||||
| //    }
 | ||||
| //
 | ||||
| //    //设置文件保存路径,如果新文件路径和旧文件路径不同,则修改路径
 | ||||
| //    if (!filePath.equals(mEntity.getDownloadPath())) {
 | ||||
| //      // 检查路径冲突
 | ||||
| //      if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", filePath)) {
 | ||||
| //        if (!isForceDownload()) {
 | ||||
| //          ALog.e(TAG, "下载失败,保存路径【" + filePath + "】已经被其它任务占用,请设置其它保存路径");
 | ||||
| //          return false;
 | ||||
| //        } else {
 | ||||
| //          ALog.w(TAG, "保存路径【" + filePath + "】已经被其它任务占用,当前任务将覆盖该路径的文件");
 | ||||
| //          CommonUtil.delTaskRecord(filePath, 1);
 | ||||
| //          setTaskWrapper(
 | ||||
| //              TaskWrapperManager.getInstance().getHttpTaskWrapper(DTaskWrapper.class, getUrl()));
 | ||||
| //        }
 | ||||
| //      }
 | ||||
| //      File oldFile = new File(mEntity.getDownloadPath());
 | ||||
| //      File newFile = new File(filePath);
 | ||||
| //      mEntity.setDownloadPath(filePath);
 | ||||
| //      mEntity.setFileName(newFile.getName());
 | ||||
| //      if (oldFile.exists()) {
 | ||||
| //        oldFile.renameTo(newFile);
 | ||||
| //        CommonUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath());
 | ||||
| //      }
 | ||||
| //    }
 | ||||
| //    return true;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 检查普通任务的下载地址
 | ||||
| //   *
 | ||||
| //   * @return {@code true}地址合法
 | ||||
| //   */
 | ||||
| //  private boolean checkUrl() {
 | ||||
| //    final String url = mEntity.getUrl();
 | ||||
| //    if (TextUtils.isEmpty(url)) {
 | ||||
| //      ALog.e(TAG, "下载失败,url为null");
 | ||||
| //      return false;
 | ||||
| //    } else if (!url.startsWith("http") && !url.startsWith("ftp")) {
 | ||||
| //      ALog.e(TAG, "下载失败,url【" + url + "】错误");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    int index = url.indexOf("://");
 | ||||
| //    if (index == -1) {
 | ||||
| //      ALog.e(TAG, "下载失败,url【" + url + "】不合法");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    if (!TextUtils.isEmpty(getNewUrl())) {
 | ||||
| //      mEntity.setUrl(getNewUrl());
 | ||||
| //    }
 | ||||
| //    return true;
 | ||||
| //  }
 | ||||
| //}
 | ||||
| @ -1,146 +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.core.upload;
 | ||||
| //
 | ||||
| //import android.support.annotation.CheckResult;
 | ||||
| //import android.support.annotation.NonNull;
 | ||||
| //import android.text.TextUtils;
 | ||||
| //import com.arialyy.aria.core.manager.TaskWrapperManager;
 | ||||
| //import com.arialyy.aria.core.queue.UploadTaskQueue;
 | ||||
| //import com.arialyy.aria.orm.DbEntity;
 | ||||
| //import com.arialyy.aria.util.ALog;
 | ||||
| //import java.io.File;
 | ||||
| //
 | ||||
| ///**
 | ||||
| // * Created by AriaL on 2018/3/9.
 | ||||
| // */
 | ||||
| //abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
 | ||||
| //    extends AbsUploadTarget<TARGET, UploadEntity, UTaskWrapper> {
 | ||||
| //
 | ||||
| //  protected String mTempUrl;
 | ||||
| //
 | ||||
| //  void initTarget(String filePath) {
 | ||||
| //    mTaskWrapper =
 | ||||
| //        TaskWrapperManager.getInstance().getHttpTaskWrapper(UTaskWrapper.class, filePath);
 | ||||
| //    mEntity = mTaskWrapper.getEntity();
 | ||||
| //    File file = new File(filePath);
 | ||||
| //    mEntity.setFileName(file.getName());
 | ||||
| //    mEntity.setFileSize(file.length());
 | ||||
| //    mTempUrl = mEntity.getUrl();
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 设置上传路径
 | ||||
| //   *
 | ||||
| //   * @param uploadUrl 上传路径
 | ||||
| //   */
 | ||||
| //  @CheckResult
 | ||||
| //  public TARGET setTempUrl(@NonNull String uploadUrl) {
 | ||||
| //    mTempUrl = uploadUrl;
 | ||||
| //    return (TARGET) this;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 上传任务是否存在
 | ||||
| //   *
 | ||||
| //   * @return {@code true}存在
 | ||||
| //   */
 | ||||
| //  @Override public boolean taskExists() {
 | ||||
| //    return DbEntity.checkDataExist(UploadEntity.class, "key=?", mEntity.getFilePath());
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 是否在上传
 | ||||
| //   *
 | ||||
| //   * @deprecated {@link #isRunning()}
 | ||||
| //   */
 | ||||
| //  public boolean isUploading() {
 | ||||
| //    return isRunning();
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  @Override public boolean isRunning() {
 | ||||
| //    UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity.getKey());
 | ||||
| //    return task != null && task.isRunning();
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  @Override protected boolean checkEntity() {
 | ||||
| //    boolean b = checkUrl() && checkFilePath();
 | ||||
| //    if (b) {
 | ||||
| //      mEntity.save();
 | ||||
| //    }
 | ||||
| //    if (mTaskWrapper.asFtp().getUrlEntity() != null && mTaskWrapper.asFtp().getUrlEntity().isFtps) {
 | ||||
| //      //if (TextUtils.isEmpty(mTaskWrapper.getUrlEntity().storePath)) {
 | ||||
| //      //  ALog.e(TAG, "证书路径为空");
 | ||||
| //      //  return false;
 | ||||
| //      //}
 | ||||
| //      if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)) {
 | ||||
| //        ALog.e(TAG, "证书别名为空");
 | ||||
| //        return false;
 | ||||
| //      }
 | ||||
| //    }
 | ||||
| //    return b;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 检查上传文件路径是否合法
 | ||||
| //   *
 | ||||
| //   * @return {@code true} 合法
 | ||||
| //   */
 | ||||
| //  private boolean checkFilePath() {
 | ||||
| //    String filePath = mEntity.getFilePath();
 | ||||
| //    if (TextUtils.isEmpty(filePath)) {
 | ||||
| //      ALog.e(TAG, "上传失败,文件路径为null");
 | ||||
| //      return false;
 | ||||
| //    } else if (!filePath.startsWith("/")) {
 | ||||
| //      ALog.e(TAG, "上传失败,文件路径【" + filePath + "】不合法");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //
 | ||||
| //    File file = new File(mEntity.getFilePath());
 | ||||
| //    if (!file.exists()) {
 | ||||
| //      ALog.e(TAG, "上传失败,文件【" + filePath + "】不存在");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    if (file.isDirectory()) {
 | ||||
| //      ALog.e(TAG, "上传失败,文件【" + filePath + "】不能是文件夹");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    return true;
 | ||||
| //  }
 | ||||
| //
 | ||||
| //  /**
 | ||||
| //   * 检查普通任务的下载地址
 | ||||
| //   *
 | ||||
| //   * @return {@code true}地址合法
 | ||||
| //   */
 | ||||
| //  protected boolean checkUrl() {
 | ||||
| //    final String url = mTempUrl;
 | ||||
| //    if (TextUtils.isEmpty(url)) {
 | ||||
| //      ALog.e(TAG, "上传失败,url为null");
 | ||||
| //      return false;
 | ||||
| //    } else if (!url.startsWith("http") && !url.startsWith("ftp")) {
 | ||||
| //      ALog.e(TAG, "上传失败,url【" + url + "】错误");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    int index = url.indexOf("://");
 | ||||
| //    if (index == -1) {
 | ||||
| //      ALog.e(TAG, "上传失败,url【" + url + "】不合法");
 | ||||
| //      return false;
 | ||||
| //    }
 | ||||
| //    mEntity.setUrl(url);
 | ||||
| //    return true;
 | ||||
| //  }
 | ||||
| //}
 | ||||
| @ -1,199 +1,194 @@ | ||||
| /* | ||||
|  * 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.core.upload.uploader; | ||||
| 
 | ||||
| import aria.apache.commons.net.ftp.FTPClient; | ||||
| import aria.apache.commons.net.ftp.FTPReply; | ||||
| import aria.apache.commons.net.ftp.OnFtpInputStreamListener; | ||||
| import com.arialyy.aria.core.common.StateConstance; | ||||
| import com.arialyy.aria.core.common.SubThreadConfig; | ||||
| import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; | ||||
| import com.arialyy.aria.core.config.BaseTaskConfig; | ||||
| import com.arialyy.aria.core.config.DownloadConfig; | ||||
| import com.arialyy.aria.core.config.UploadConfig; | ||||
| import com.arialyy.aria.core.inf.IEventListener; | ||||
| import com.arialyy.aria.core.upload.UploadEntity; | ||||
| import com.arialyy.aria.core.upload.UTaskWrapper; | ||||
| import com.arialyy.aria.exception.AriaIOException; | ||||
| import com.arialyy.aria.exception.TaskException; | ||||
| import com.arialyy.aria.util.ALog; | ||||
| import com.arialyy.aria.util.BufferedRandomAccessFile; | ||||
| import java.io.IOException; | ||||
| import java.io.UnsupportedEncodingException; | ||||
| 
 | ||||
| /** | ||||
|  * Created by Aria.Lao on 2017/7/28. FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 | ||||
|  */ | ||||
| class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UTaskWrapper> { | ||||
|   private final String TAG = "FtpThreadTask"; | ||||
|   private String dir, remotePath; | ||||
| 
 | ||||
|   FtpThreadTask(StateConstance constance, IEventListener listener, | ||||
|       SubThreadConfig<UTaskWrapper> info) { | ||||
|     super(constance, listener, info); | ||||
|   } | ||||
| 
 | ||||
|   @Override public int getMaxSpeed() { | ||||
|     return getTaskConfig().getMaxSpeed(); | ||||
|   } | ||||
| 
 | ||||
|   @Override protected UploadConfig getTaskConfig() { | ||||
|     return mTaskWrapper.getConfig(); | ||||
|   } | ||||
| 
 | ||||
|   @Override public FtpThreadTask call() throws Exception { | ||||
|     super.call(); | ||||
|     //当前子线程的下载位置
 | ||||
|     mChildCurrentLocation = mConfig.START_LOCATION; | ||||
|     FTPClient client = null; | ||||
|     BufferedRandomAccessFile file = null; | ||||
|     try { | ||||
|       ALog.d(TAG, | ||||
|           String.format("任务【%s】线程__%s__开始上传【开始位置 : %s,结束位置:%s】", mConfig.TEMP_FILE.getName(), | ||||
|               mConfig.THREAD_ID, mConfig.START_LOCATION, mConfig.END_LOCATION)); | ||||
|       client = createClient(); | ||||
|       if (client == null) { | ||||
|         return this; | ||||
|       } | ||||
|       initPath(); | ||||
|       client.makeDirectory(dir); | ||||
|       client.changeWorkingDirectory(dir); | ||||
|       client.setRestartOffset(mConfig.START_LOCATION); | ||||
|       int reply = client.getReplyCode(); | ||||
|       if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) { | ||||
|         fail(mChildCurrentLocation, | ||||
|             new AriaIOException(TAG, | ||||
|                 String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, | ||||
|                     client.getReplyString(), mEntity.getFilePath()))); | ||||
|         client.disconnect(); | ||||
|         return this; | ||||
|       } | ||||
| 
 | ||||
|       file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); | ||||
|       if (mConfig.START_LOCATION != 0) { | ||||
|         //file.skipBytes((int) mConfig.START_LOCATION);
 | ||||
|         file.seek(mConfig.START_LOCATION); | ||||
|       } | ||||
|       boolean complete = upload(client, file); | ||||
|       if (!complete || isBreak()) { | ||||
|         return this; | ||||
|       } | ||||
|       ALog.i(TAG, | ||||
|           String.format("任务【%s】线程__%s__上传完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID)); | ||||
|       writeConfig(true, mConfig.END_LOCATION); | ||||
|       STATE.COMPLETE_THREAD_NUM++; | ||||
|       if (STATE.isComplete()) { | ||||
|         STATE.TASK_RECORD.deleteData(); | ||||
|         STATE.isRunning = false; | ||||
|         mListener.onComplete(); | ||||
|       } | ||||
|       if (STATE.isFail()) { | ||||
|         STATE.isRunning = false; | ||||
|         mListener.onFail(false, new TaskException(TAG, | ||||
|             String.format("上传失败,filePath: %s, uploadUrl: %s", mEntity.getFilePath(), mConfig.URL))); | ||||
|       } | ||||
|     } catch (IOException e) { | ||||
|       fail(mChildCurrentLocation, new AriaIOException(TAG, | ||||
|           String.format("上传失败,filePath: %s, uploadUrl: %s", mEntity.getFilePath(), mConfig.URL))); | ||||
|     } catch (Exception e) { | ||||
|       fail(mChildCurrentLocation, new AriaIOException(TAG, null, e)); | ||||
|     } finally { | ||||
|       try { | ||||
|         if (file != null) { | ||||
|           file.close(); | ||||
|         } | ||||
|         if (client != null && client.isConnected()) { | ||||
|           client.disconnect(); | ||||
|         } | ||||
|       } catch (IOException e) { | ||||
|         e.printStackTrace(); | ||||
|       } | ||||
|     } | ||||
|     return this; | ||||
|   } | ||||
| 
 | ||||
|   private void initPath() throws UnsupportedEncodingException { | ||||
|     dir = new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), | ||||
|         SERVER_CHARSET); | ||||
|     remotePath = new String( | ||||
|         ("/" | ||||
|             + mTaskWrapper.asFtp().getUrlEntity().remotePath | ||||
|             + "/" | ||||
|             + mEntity.getFileName()).getBytes( | ||||
|             charSet), | ||||
|         SERVER_CHARSET); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 上传 | ||||
|    * | ||||
|    * @return {@code true}上传成功、{@code false} 上传失败 | ||||
|    */ | ||||
|   private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis) | ||||
|       throws IOException { | ||||
| 
 | ||||
|     try { | ||||
|       ALog.d(TAG, String.format("remotePath: %s", remotePath)); | ||||
|       client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { | ||||
|         boolean isStoped = false; | ||||
| 
 | ||||
|         @Override public void onFtpInputStream(FTPClient client, long totalBytesTransferred, | ||||
|             int bytesTransferred, long streamSize) { | ||||
|           try { | ||||
|             if (isBreak() && !isStoped) { | ||||
|               isStoped = true; | ||||
|               client.abor(); | ||||
|             } | ||||
|             if (mSpeedBandUtil != null) { | ||||
|               mSpeedBandUtil.limitNextBytes(bytesTransferred); | ||||
|             } | ||||
|             progress(bytesTransferred); | ||||
|           } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|           } | ||||
|         } | ||||
|       }); | ||||
|     } catch (IOException e) { | ||||
|       String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(), | ||||
|           client.getReplyString(), mEntity.getFilePath()); | ||||
|       if (client.isConnected()) { | ||||
|         client.disconnect(); | ||||
|       } | ||||
|       if (e.getMessage().contains("AriaIOException caught while copying")) { | ||||
|         e.printStackTrace(); | ||||
|       } else { | ||||
|         fail(mChildCurrentLocation, | ||||
|             new AriaIOException(TAG, msg, e)); | ||||
|       } | ||||
|       return false; | ||||
|     } | ||||
| 
 | ||||
|     int reply = client.getReplyCode(); | ||||
|     if (!FTPReply.isPositiveCompletion(reply)) { | ||||
|       if (reply != FTPReply.TRANSFER_ABORTED) { | ||||
|         fail(mChildCurrentLocation, | ||||
|             new AriaIOException(TAG, | ||||
|                 String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, | ||||
|                     client.getReplyString(), mEntity.getFilePath()))); | ||||
|       } | ||||
|       if (client.isConnected()) { | ||||
|         client.disconnect(); | ||||
|       } | ||||
|       return false; | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
| } | ||||
| /* | ||||
|  * 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.core.upload.uploader; | ||||
| 
 | ||||
| import aria.apache.commons.net.ftp.FTPClient; | ||||
| import aria.apache.commons.net.ftp.FTPReply; | ||||
| import aria.apache.commons.net.ftp.OnFtpInputStreamListener; | ||||
| import com.arialyy.aria.core.common.StateConstance; | ||||
| import com.arialyy.aria.core.common.SubThreadConfig; | ||||
| import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; | ||||
| import com.arialyy.aria.core.config.BaseTaskConfig; | ||||
| import com.arialyy.aria.core.config.DownloadConfig; | ||||
| import com.arialyy.aria.core.config.UploadConfig; | ||||
| import com.arialyy.aria.core.inf.IEventListener; | ||||
| import com.arialyy.aria.core.upload.UploadEntity; | ||||
| import com.arialyy.aria.core.upload.UTaskWrapper; | ||||
| import com.arialyy.aria.exception.AriaIOException; | ||||
| import com.arialyy.aria.exception.TaskException; | ||||
| import com.arialyy.aria.util.ALog; | ||||
| import com.arialyy.aria.util.BufferedRandomAccessFile; | ||||
| import java.io.IOException; | ||||
| import java.io.UnsupportedEncodingException; | ||||
| 
 | ||||
| /** | ||||
|  * Created by Aria.Lao on 2017/7/28. FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 | ||||
|  */ | ||||
| class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UTaskWrapper> { | ||||
|   private final String TAG = "FtpThreadTask"; | ||||
|   private String dir, remotePath; | ||||
| 
 | ||||
|   FtpThreadTask(StateConstance constance, IEventListener listener, | ||||
|       SubThreadConfig<UTaskWrapper> info) { | ||||
|     super(constance, listener, info); | ||||
|   } | ||||
| 
 | ||||
|   @Override public int getMaxSpeed() { | ||||
|     return getTaskConfig().getMaxSpeed(); | ||||
|   } | ||||
| 
 | ||||
|   @Override protected UploadConfig getTaskConfig() { | ||||
|     return mTaskWrapper.getConfig(); | ||||
|   } | ||||
| 
 | ||||
|   @Override public FtpThreadTask call() throws Exception { | ||||
|     super.call(); | ||||
|     //当前子线程的下载位置
 | ||||
|     mChildCurrentLocation = mConfig.START_LOCATION; | ||||
|     FTPClient client = null; | ||||
|     BufferedRandomAccessFile file = null; | ||||
|     try { | ||||
|       ALog.d(TAG, | ||||
|           String.format("任务【%s】线程__%s__开始上传【开始位置 : %s,结束位置:%s】", mConfig.TEMP_FILE.getName(), | ||||
|               mConfig.THREAD_ID, mConfig.START_LOCATION, mConfig.END_LOCATION)); | ||||
|       client = createClient(); | ||||
|       if (client == null) { | ||||
|         return this; | ||||
|       } | ||||
|       initPath(); | ||||
|       client.makeDirectory(dir); | ||||
|       client.changeWorkingDirectory(dir); | ||||
|       client.setRestartOffset(mConfig.START_LOCATION); | ||||
|       int reply = client.getReplyCode(); | ||||
|       if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) { | ||||
|         fail(mChildCurrentLocation, | ||||
|             new AriaIOException(TAG, | ||||
|                 String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, | ||||
|                     client.getReplyString(), mEntity.getFilePath()))); | ||||
|         client.disconnect(); | ||||
|         return this; | ||||
|       } | ||||
| 
 | ||||
|       file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); | ||||
|       if (mConfig.START_LOCATION != 0) { | ||||
|         //file.skipBytes((int) mConfig.START_LOCATION);
 | ||||
|         file.seek(mConfig.START_LOCATION); | ||||
|       } | ||||
|       boolean complete = upload(client, file); | ||||
|       if (!complete || isBreak()) { | ||||
|         return this; | ||||
|       } | ||||
|       ALog.i(TAG, | ||||
|           String.format("任务【%s】线程__%s__上传完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID)); | ||||
|       writeConfig(true, mConfig.END_LOCATION); | ||||
|       STATE.COMPLETE_THREAD_NUM++; | ||||
|       if (STATE.isComplete()) { | ||||
|         STATE.TASK_RECORD.deleteData(); | ||||
|         STATE.isRunning = false; | ||||
|         mListener.onComplete(); | ||||
|       } | ||||
|       if (STATE.isFail()) { | ||||
|         STATE.isRunning = false; | ||||
|         mListener.onFail(false, new TaskException(TAG, | ||||
|             String.format("上传失败,filePath: %s, uploadUrl: %s", mEntity.getFilePath(), mConfig.URL))); | ||||
|       } | ||||
|     } catch (IOException e) { | ||||
|       fail(mChildCurrentLocation, new AriaIOException(TAG, | ||||
|           String.format("上传失败,filePath: %s, uploadUrl: %s", mEntity.getFilePath(), mConfig.URL))); | ||||
|     } catch (Exception e) { | ||||
|       fail(mChildCurrentLocation, new AriaIOException(TAG, null, e)); | ||||
|     } finally { | ||||
|       try { | ||||
|         if (file != null) { | ||||
|           file.close(); | ||||
|         } | ||||
|         if (client != null && client.isConnected()) { | ||||
|           client.disconnect(); | ||||
|         } | ||||
|       } catch (IOException e) { | ||||
|         e.printStackTrace(); | ||||
|       } | ||||
|     } | ||||
|     return this; | ||||
|   } | ||||
| 
 | ||||
|   private void initPath() throws UnsupportedEncodingException { | ||||
|     dir = new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), | ||||
|         SERVER_CHARSET); | ||||
|     remotePath = new String(String.format("%s/%s", mTaskWrapper.asFtp().getUrlEntity().remotePath, | ||||
|         mEntity.getFileName()).getBytes(charSet), SERVER_CHARSET); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 上传 | ||||
|    * | ||||
|    * @return {@code true}上传成功、{@code false} 上传失败 | ||||
|    */ | ||||
|   private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis) | ||||
|       throws IOException { | ||||
| 
 | ||||
|     try { | ||||
|       ALog.d(TAG, String.format("remotePath: %s", remotePath)); | ||||
|       client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { | ||||
|         boolean isStoped = false; | ||||
| 
 | ||||
|         @Override public void onFtpInputStream(FTPClient client, long totalBytesTransferred, | ||||
|             int bytesTransferred, long streamSize) { | ||||
|           try { | ||||
|             if (isBreak() && !isStoped) { | ||||
|               isStoped = true; | ||||
|               client.abor(); | ||||
|             } | ||||
|             if (mSpeedBandUtil != null) { | ||||
|               mSpeedBandUtil.limitNextBytes(bytesTransferred); | ||||
|             } | ||||
|             progress(bytesTransferred); | ||||
|           } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|           } | ||||
|         } | ||||
|       }); | ||||
|     } catch (IOException e) { | ||||
|       String msg = String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", client.getReplyCode(), | ||||
|           client.getReplyString(), mEntity.getFilePath()); | ||||
|       if (client.isConnected()) { | ||||
|         client.disconnect(); | ||||
|       } | ||||
|       if (e.getMessage().contains("AriaIOException caught while copying")) { | ||||
|         e.printStackTrace(); | ||||
|       } else { | ||||
|         fail(mChildCurrentLocation, | ||||
|             new AriaIOException(TAG, msg, e)); | ||||
|       } | ||||
|       return false; | ||||
|     } | ||||
| 
 | ||||
|     int reply = client.getReplyCode(); | ||||
|     if (!FTPReply.isPositiveCompletion(reply)) { | ||||
|       if (reply != FTPReply.TRANSFER_ABORTED) { | ||||
|         fail(mChildCurrentLocation, | ||||
|             new AriaIOException(TAG, | ||||
|                 String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, | ||||
|                     client.getReplyString(), mEntity.getFilePath()))); | ||||
|       } | ||||
|       if (client.isConnected()) { | ||||
|         client.disconnect(); | ||||
|       } | ||||
|       return false; | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,24 @@ | ||||
| /* | ||||
|  * 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.exception; | ||||
| 
 | ||||
| public class ParamException extends RuntimeException { | ||||
|   private static final String ARIA_NET_EXCEPTION = "Aria Params Exception:"; | ||||
| 
 | ||||
|   public ParamException(String message) { | ||||
|     super(String.format("%s%s", ARIA_NET_EXCEPTION, message)); | ||||
|   } | ||||
| } | ||||
| @ -1,290 +1,290 @@ | ||||
| /* | ||||
|  * 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.orm; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| /** | ||||
|  * Created by lyy on 2015/11/2. 所有数据库实体父类 | ||||
|  */ | ||||
| public abstract class DbEntity { | ||||
|   private static final Object LOCK = new Object(); | ||||
|   protected long rowID = -1; | ||||
| 
 | ||||
|   protected DbEntity() { | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询关联数据 | ||||
|    * <code> | ||||
|    * DbEntity.findRelationData(DGEntityWrapper.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param expression 查询条件 | ||||
|    */ | ||||
|   public static <T extends AbsDbWrapper> List<T> findRelationData(Class<T> clazz, | ||||
|       String... expression) { | ||||
|     return DelegateWrapper.getInstance().findRelationData(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 分页查询关联数据 | ||||
|    * | ||||
|    * <code> | ||||
|    * DbEntity.findRelationData(DGEntityWrapper.class, 0, 10, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param expression 查询条件 | ||||
|    * @param page 需要查询的页数,从1开始,如果page小于1 或 num 小于1,返回null | ||||
|    * @param num 每页返回的数量 | ||||
|    * @return 没有数据返回null,如果页数大于总页数,返回null | ||||
|    */ | ||||
|   public static <T extends AbsDbWrapper> List<T> findRelationData(Class<T> clazz, int page, int num, | ||||
|       String... expression) { | ||||
|     if (page < 1 || num < 1) { | ||||
|       return null; | ||||
|     } | ||||
|     return DelegateWrapper.getInstance().findRelationData(clazz, page, num, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查某个字段的值是否存在 | ||||
|    * | ||||
|    * @param expression 字段和值"downloadPath=?" | ||||
|    * @return {@code true}该字段的对应的value已存在 | ||||
|    */ | ||||
|   public static boolean checkDataExist(Class clazz, String... expression) { | ||||
|     return DelegateWrapper.getInstance().checkDataExist(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 清空表数据 | ||||
|    */ | ||||
|   public static <T extends DbEntity> void clean(Class<T> clazz) { | ||||
|     DelegateWrapper.getInstance().clean(clazz); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 直接执行sql语句 | ||||
|    */ | ||||
|   public static void exeSql(String sql) { | ||||
|     DelegateWrapper.getInstance().exeSql(sql); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询所有数据 | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findAllData(Class<T> clazz) { | ||||
|     return DelegateWrapper.getInstance().findAllData(clazz); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询第一条数据 | ||||
|    */ | ||||
|   public static <T extends DbEntity> T findFirst(Class<T> clazz) { | ||||
|     List<T> list = findAllData(clazz); | ||||
|     return (list == null || list.size() == 0) ? null : list.get(0); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询一组数据 | ||||
|    * <code> | ||||
|    * DbEntity.findFirst(DownloadEntity.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, String... expression) { | ||||
|     return DelegateWrapper.getInstance().findData(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 分页查询数据 | ||||
|    * <code> | ||||
|    * DbEntity.findFirst(DownloadEntity.class, 0, 10, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param page 需要查询的页数,从1开始,如果page小于1 或 num 小于1,返回null | ||||
|    * @param num 每页返回的数量 | ||||
|    * @return 没有数据返回null,如果页数大于总页数,返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, int page, int num, | ||||
|       String... expression) { | ||||
|     if (page < 1 || num < 1) { | ||||
|       return null; | ||||
|     } | ||||
|     return DelegateWrapper.getInstance().findData(clazz, page, num, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 模糊查询一组数据 | ||||
|    * <code> | ||||
|    * DbEntity.findDataByFuzzy(DownloadEntity.class, "downloadUrl like http://"); | ||||
|    * </code> | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) { | ||||
|     return DelegateWrapper.getInstance().findDataByFuzzy(clazz, conditions); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 模糊查询一组数据 | ||||
|    * <code> | ||||
|    * DbEntity.findDataByFuzzy(DownloadEntity.class, 0, 10, "downloadUrl like http://"); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param page 需要查询的页数,从1开始,如果page小于1 或 num 小于1,返回null | ||||
|    * @param num 每页返回的数量 | ||||
|    * @return 没有数据返回null,如果页数大于总页数,返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, int page, int num, | ||||
|       String conditions) { | ||||
|     return DelegateWrapper.getInstance().findDataByFuzzy(clazz, page, num, conditions); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询一行数据 | ||||
|    * <code> | ||||
|    * DbEntity.findFirst(DownloadEntity.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> T findFirst(Class<T> clazz, String... expression) { | ||||
|     DelegateWrapper util = DelegateWrapper.getInstance(); | ||||
|     List<T> datas = util.findData(clazz, expression); | ||||
|     return datas == null ? null : datas.size() > 0 ? datas.get(0) : null; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 插入多条数据 | ||||
|    */ | ||||
|   public static void insertManyData(List<DbEntity> entities) { | ||||
|     checkListData(entities); | ||||
|     DelegateWrapper.getInstance().insertManyData(entities); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 修改多条数据 | ||||
|    */ | ||||
|   public static void updateManyData(List<DbEntity> entities) { | ||||
|     checkListData(entities); | ||||
|     DelegateWrapper.getInstance().updateManyData(entities); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 保存多条数据,通过rowID来判断记录存在以否,如果数据库已有记录,则更新该记录;如果数据库中没有记录,则保存该记录 | ||||
|    */ | ||||
|   public static void saveAll(List<DbEntity> entities) { | ||||
|     checkListData(entities); | ||||
|     List<DbEntity> insertD = new ArrayList<>(); | ||||
|     List<DbEntity> updateD = new ArrayList<>(); | ||||
|     DelegateWrapper wrapper = DelegateWrapper.getInstance(); | ||||
|     for (DbEntity entity : entities) { | ||||
|       if (entity.rowID == -1) { | ||||
|         insertD.add(entity); | ||||
|         continue; | ||||
|       } | ||||
|       if (wrapper.isExist(entity.getClass(), entity.rowID)) { | ||||
|         insertD.add(entity); | ||||
|       } else { | ||||
|         updateD.add(entity); | ||||
|       } | ||||
|     } | ||||
|     if (!insertD.isEmpty()) { | ||||
|       wrapper.insertManyData(insertD); | ||||
|     } else { | ||||
|       wrapper.updateManyData(updateD); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查批量操作的列表数据,如果数据为空,抛出{@link NullPointerException} | ||||
|    */ | ||||
|   private static void checkListData(List<DbEntity> entities) { | ||||
|     if (entities == null || entities.isEmpty()) { | ||||
|       throw new NullPointerException("列表数据为空"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 删除当前数据 | ||||
|    */ | ||||
|   public void deleteData() { | ||||
|     deleteData(getClass(), "rowid=?", rowID + ""); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 根据条件删除数据 | ||||
|    * <code> | ||||
|    * DbEntity.deleteData(DownloadEntity.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    */ | ||||
|   public static <T extends DbEntity> void deleteData(Class<T> clazz, String... expression) { | ||||
|     DelegateWrapper util = DelegateWrapper.getInstance(); | ||||
|     util.delData(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 修改数据 | ||||
|    */ | ||||
|   public void update() { | ||||
|     DelegateWrapper.getInstance().updateData(this); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 保存自身,如果表中已经有数据,则更新数据,否则插入数据 只有 target中checkEntity成功后才能保存,创建实体部分也不允许保存 | ||||
|    */ | ||||
|   public void save() { | ||||
|     synchronized (LOCK) { | ||||
|       if (thisIsExist()) { | ||||
|         update(); | ||||
|       } else { | ||||
|         insert(); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查找数据在表中是否存在 | ||||
|    */ | ||||
|   private boolean thisIsExist() { | ||||
|     DelegateWrapper util = DelegateWrapper.getInstance(); | ||||
|     return rowID != -1 && util.isExist(getClass(), rowID); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 表是否存在 | ||||
|    * | ||||
|    * @return {@code true} 存在 | ||||
|    */ | ||||
|   public static boolean tableExists(Class<DbEntity> clazz) { | ||||
|     return DelegateWrapper.getInstance().tableExists(clazz); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 插入数据,只有 target中checkEntity成功后才能插入,创建实体部分也不允许操作 | ||||
|    */ | ||||
|   public void insert() { | ||||
|     DelegateWrapper.getInstance().insertData(this); | ||||
|   } | ||||
| /* | ||||
|  * 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.orm; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| /** | ||||
|  * Created by lyy on 2015/11/2. 所有数据库实体父类 | ||||
|  */ | ||||
| public abstract class DbEntity { | ||||
|   private static final Object LOCK = new Object(); | ||||
|   protected long rowID = -1; | ||||
| 
 | ||||
|   protected DbEntity() { | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询关联数据 | ||||
|    * <code> | ||||
|    * DbEntity.findRelationData(DGEntityWrapper.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param expression 查询条件 | ||||
|    */ | ||||
|   public static <T extends AbsDbWrapper> List<T> findRelationData(Class<T> clazz, | ||||
|       String... expression) { | ||||
|     return DelegateWrapper.getInstance().findRelationData(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 分页查询关联数据 | ||||
|    * | ||||
|    * <code> | ||||
|    * DbEntity.findRelationData(DGEntityWrapper.class, 0, 10, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param expression 查询条件 | ||||
|    * @param page 需要查询的页数,从1开始,如果page小于1 或 num 小于1,返回null | ||||
|    * @param num 每页返回的数量 | ||||
|    * @return 没有数据返回null,如果页数大于总页数,返回null | ||||
|    */ | ||||
|   public static <T extends AbsDbWrapper> List<T> findRelationData(Class<T> clazz, int page, int num, | ||||
|       String... expression) { | ||||
|     if (page < 1 || num < 1) { | ||||
|       return null; | ||||
|     } | ||||
|     return DelegateWrapper.getInstance().findRelationData(clazz, page, num, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查某个字段的值是否存在 | ||||
|    * | ||||
|    * @param expression 字段和值"downloadPath=?" | ||||
|    * @return {@code true}该字段的对应的value已存在 | ||||
|    */ | ||||
|   public static boolean checkDataExist(Class clazz, String... expression) { | ||||
|     return DelegateWrapper.getInstance().checkDataExist(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 清空表数据 | ||||
|    */ | ||||
|   public static <T extends DbEntity> void clean(Class<T> clazz) { | ||||
|     DelegateWrapper.getInstance().clean(clazz); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 直接执行sql语句 | ||||
|    */ | ||||
|   public static void exeSql(String sql) { | ||||
|     DelegateWrapper.getInstance().exeSql(sql); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询所有数据 | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findAllData(Class<T> clazz) { | ||||
|     return DelegateWrapper.getInstance().findAllData(clazz); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询第一条数据 | ||||
|    */ | ||||
|   public static <T extends DbEntity> T findFirst(Class<T> clazz) { | ||||
|     List<T> list = findAllData(clazz); | ||||
|     return (list == null || list.size() == 0) ? null : list.get(0); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询一组数据 | ||||
|    * <code> | ||||
|    * DbEntity.findFirst(DownloadEntity.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, String... expression) { | ||||
|     return DelegateWrapper.getInstance().findData(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 分页查询数据 | ||||
|    * <code> | ||||
|    * DbEntity.findFirst(DownloadEntity.class, 0, 10, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param page 需要查询的页数,从1开始,如果page小于1 或 num 小于1,返回null | ||||
|    * @param num 每页返回的数量 | ||||
|    * @return 没有数据返回null,如果页数大于总页数,返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDatas(Class<T> clazz, int page, int num, | ||||
|       String... expression) { | ||||
|     if (page < 1 || num < 1) { | ||||
|       return null; | ||||
|     } | ||||
|     return DelegateWrapper.getInstance().findData(clazz, page, num, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 模糊查询一组数据 | ||||
|    * <code> | ||||
|    * DbEntity.findDataByFuzzy(DownloadEntity.class, "downloadUrl like http://"); | ||||
|    * </code> | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, String conditions) { | ||||
|     return DelegateWrapper.getInstance().findDataByFuzzy(clazz, conditions); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 模糊查询一组数据 | ||||
|    * <code> | ||||
|    * DbEntity.findDataByFuzzy(DownloadEntity.class, 0, 10, "downloadUrl like http://"); | ||||
|    * </code> | ||||
|    * | ||||
|    * @param page 需要查询的页数,从1开始,如果page小于1 或 num 小于1,返回null | ||||
|    * @param num 每页返回的数量 | ||||
|    * @return 没有数据返回null,如果页数大于总页数,返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> List<T> findDataByFuzzy(Class<T> clazz, int page, int num, | ||||
|       String conditions) { | ||||
|     return DelegateWrapper.getInstance().findDataByFuzzy(clazz, page, num, conditions); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查询一行数据 | ||||
|    * <code> | ||||
|    * DbEntity.findFirst(DownloadEntity.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    * | ||||
|    * @return 没有数据返回null | ||||
|    */ | ||||
|   public static <T extends DbEntity> T findFirst(Class<T> clazz, String... expression) { | ||||
|     DelegateWrapper util = DelegateWrapper.getInstance(); | ||||
|     List<T> datas = util.findData(clazz, expression); | ||||
|     return datas == null ? null : datas.size() > 0 ? datas.get(0) : null; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 插入多条数据 | ||||
|    */ | ||||
|   public static void insertManyData(List<DbEntity> entities) { | ||||
|     checkListData(entities); | ||||
|     DelegateWrapper.getInstance().insertManyData(entities); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 修改多条数据 | ||||
|    */ | ||||
|   public static void updateManyData(List<DbEntity> entities) { | ||||
|     checkListData(entities); | ||||
|     DelegateWrapper.getInstance().updateManyData(entities); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 保存多条数据,通过rowID来判断记录存在以否,如果数据库已有记录,则更新该记录;如果数据库中没有记录,则保存该记录 | ||||
|    */ | ||||
|   public static <T extends DbEntity> void saveAll(List<T> entities) { | ||||
|     checkListData(entities); | ||||
|     List<DbEntity> insertD = new ArrayList<>(); | ||||
|     List<DbEntity> updateD = new ArrayList<>(); | ||||
|     DelegateWrapper wrapper = DelegateWrapper.getInstance(); | ||||
|     for (DbEntity entity : entities) { | ||||
|       if (entity.rowID == -1) { | ||||
|         insertD.add(entity); | ||||
|         continue; | ||||
|       } | ||||
|       if (wrapper.isExist(entity.getClass(), entity.rowID)) { | ||||
|         updateD.add(entity); | ||||
|       } else { | ||||
|         insertD.add(entity); | ||||
|       } | ||||
|     } | ||||
|     if (!insertD.isEmpty()) { | ||||
|       wrapper.insertManyData(insertD); | ||||
|     } else { | ||||
|       wrapper.updateManyData(updateD); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查批量操作的列表数据,如果数据为空,抛出{@link NullPointerException} | ||||
|    */ | ||||
|   private static <T extends DbEntity> void checkListData(List<T> entities) { | ||||
|     if (entities == null || entities.isEmpty()) { | ||||
|       throw new NullPointerException("列表数据为空"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 删除当前数据 | ||||
|    */ | ||||
|   public void deleteData() { | ||||
|     deleteData(getClass(), "rowid=?", rowID + ""); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 根据条件删除数据 | ||||
|    * <code> | ||||
|    * DbEntity.deleteData(DownloadEntity.class, "downloadUrl=?", downloadUrl); | ||||
|    * </code> | ||||
|    */ | ||||
|   public static <T extends DbEntity> void deleteData(Class<T> clazz, String... expression) { | ||||
|     DelegateWrapper util = DelegateWrapper.getInstance(); | ||||
|     util.delData(clazz, expression); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 修改数据 | ||||
|    */ | ||||
|   public void update() { | ||||
|     DelegateWrapper.getInstance().updateData(this); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 保存自身,如果表中已经有数据,则更新数据,否则插入数据 只有 target中checkEntity成功后才能保存,创建实体部分也不允许保存 | ||||
|    */ | ||||
|   public void save() { | ||||
|     synchronized (LOCK) { | ||||
|       if (thisIsExist()) { | ||||
|         update(); | ||||
|       } else { | ||||
|         insert(); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 查找数据在表中是否存在 | ||||
|    */ | ||||
|   private boolean thisIsExist() { | ||||
|     DelegateWrapper util = DelegateWrapper.getInstance(); | ||||
|     return rowID != -1 && util.isExist(getClass(), rowID); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 表是否存在 | ||||
|    * | ||||
|    * @return {@code true} 存在 | ||||
|    */ | ||||
|   public static boolean tableExists(Class<DbEntity> clazz) { | ||||
|     return DelegateWrapper.getInstance().tableExists(clazz); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 插入数据,只有 target中checkEntity成功后才能插入,创建实体部分也不允许操作 | ||||
|    */ | ||||
|   public void insert() { | ||||
|     DelegateWrapper.getInstance().insertData(this); | ||||
|   } | ||||
| } | ||||
| @ -1,238 +1,254 @@ | ||||
| /* | ||||
|  * 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 com.arialyy.aria.core.download.DTaskWrapper; | ||||
| import com.arialyy.aria.core.download.DownloadEntity; | ||||
| import com.arialyy.aria.core.inf.AbsTaskWrapper; | ||||
| import com.arialyy.aria.core.upload.UTaskWrapper; | ||||
| import com.arialyy.aria.core.upload.UploadEntity; | ||||
| import java.io.File; | ||||
| import java.util.List; | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
| 
 | ||||
| /** | ||||
|  * Created by Lyy on 2016/9/23. | ||||
|  * 检查帮助类 | ||||
|  */ | ||||
| public class CheckUtil { | ||||
|   private static final String TAG = "CheckUtil"; | ||||
| 
 | ||||
|   /** | ||||
|    * 判空 | ||||
|    */ | ||||
|   public static void checkNull(Object obj) { | ||||
|     if (obj == null) throw new IllegalArgumentException("不能传入空对象"); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查分页数据,需要查询的页数,从1开始,如果page小于1 或 num 小于1,则抛出{@link NullPointerException} | ||||
|    * @param page 从1 开始 | ||||
|    * @param num  每页数量 | ||||
|    */ | ||||
|   public static void checkPageParams(int page, int num){ | ||||
|     if (page < 1 || num < 1) throw new NullPointerException("page和num不能小于1"); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查sql的expression是否合法 | ||||
|    */ | ||||
|   public static void checkSqlExpression(String... expression) { | ||||
|     if (expression.length == 0) { | ||||
|       throw new IllegalArgumentException("sql语句表达式不能为null"); | ||||
|     } | ||||
|     if (expression.length == 1) { | ||||
|       throw new IllegalArgumentException("表达式需要写入参数"); | ||||
|     } | ||||
|     String where = expression[0]; | ||||
|     if (!where.contains("?")) { | ||||
|       throw new IllegalArgumentException("请在where语句的'='后编写?"); | ||||
|     } | ||||
|     Pattern pattern = Pattern.compile("\\?"); | ||||
|     Matcher matcher = pattern.matcher(where); | ||||
|     int count = 0; | ||||
|     while (matcher.find()) { | ||||
|       count++; | ||||
|     } | ||||
|     if (count < expression.length - 1) { | ||||
|       throw new IllegalArgumentException("条件语句的?个数不能小于参数个数"); | ||||
|     } | ||||
|     if (count > expression.length - 1) { | ||||
|       throw new IllegalArgumentException("条件语句的?个数不能大于参数个数"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查下载实体 | ||||
|    */ | ||||
|   public static void checkDownloadEntity(DownloadEntity entity) { | ||||
|     checkUrlInvalidThrow(entity.getUrl()); | ||||
|     entity.setUrl(entity.getUrl()); | ||||
|     checkPath(entity.getDownloadPath()); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测下载链接是否为null | ||||
|    */ | ||||
|   public static void checkPath(String path) { | ||||
|     if (TextUtils.isEmpty(path)) { | ||||
|       throw new IllegalArgumentException("保存路径不能为null"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测url是否合法,如果url不合法,将抛异常 | ||||
|    */ | ||||
|   public static void checkUrlInvalidThrow(String url) { | ||||
|     if (TextUtils.isEmpty(url)) { | ||||
|       throw new IllegalArgumentException("url不能为null"); | ||||
|     } else if (!url.startsWith("http") && !url.startsWith("ftp")) { | ||||
|       throw new IllegalArgumentException("url错误"); | ||||
|     } | ||||
|     int index = url.indexOf("://"); | ||||
|     if (index == -1) { | ||||
|       throw new IllegalArgumentException("url不合法"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测url是否合法 | ||||
|    * | ||||
|    * @return {@code true} 合法,{@code false} 非法 | ||||
|    */ | ||||
|   public static boolean checkUrl(String url) { | ||||
|     if (TextUtils.isEmpty(url)) { | ||||
|       ALog.e(TAG, "url不能为null"); | ||||
|       return false; | ||||
|     } else if (!url.startsWith("http") && !url.startsWith("ftp")) { | ||||
|       ALog.e(TAG, "url【" + url + "】错误"); | ||||
|       return false; | ||||
|     } | ||||
|     int index = url.indexOf("://"); | ||||
|     if (index == -1) { | ||||
|       ALog.e(TAG, "url【" + url + "】不合法"); | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测下载链接组是否为null | ||||
|    */ | ||||
|   public static void checkDownloadUrls(List<String> urls) { | ||||
|     if (urls == null || urls.isEmpty()) { | ||||
|       throw new IllegalArgumentException("链接组不能为null"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查下载任务组保存路径 | ||||
|    */ | ||||
|   public static void checkDownloadPaths(List<String> paths) { | ||||
|     if (paths == null || paths.isEmpty()) { | ||||
|       throw new IllegalArgumentException("链接保存路径不能为null"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测上传地址是否为null | ||||
|    */ | ||||
|   public static void checkUploadPath(String uploadPath) { | ||||
|     if (TextUtils.isEmpty(uploadPath)) { | ||||
|       throw new IllegalArgumentException("上传地址不能为null"); | ||||
|     } | ||||
|     File file = new File(uploadPath); | ||||
|     if (!file.exists()) { | ||||
|       throw new IllegalArgumentException("上传文件不存在"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查任务实体 | ||||
|    */ | ||||
|   public static void checkTaskEntity(AbsTaskWrapper entity) { | ||||
|     if (entity instanceof DTaskWrapper) { | ||||
|       checkDownloadTaskEntity(((DTaskWrapper) entity).getEntity()); | ||||
|     } else if (entity instanceof UTaskWrapper) { | ||||
|       checkUploadTaskEntity(((UTaskWrapper) entity).getEntity()); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查命令实体 | ||||
|    * | ||||
|    * @param checkType 删除命令和停止命令不需要检查下载链接和保存路径 | ||||
|    * @return {@code false}实体无效 | ||||
|    */ | ||||
|   public static boolean checkCmdEntity(AbsTaskWrapper entity, boolean checkType) { | ||||
|     boolean b = false; | ||||
|     if (entity instanceof DTaskWrapper) { | ||||
|       DownloadEntity entity1 = ((DTaskWrapper) entity).getEntity(); | ||||
|       if (entity1 == null) { | ||||
|         ALog.e(TAG, "下载实体不能为空"); | ||||
|       } else if (checkType && TextUtils.isEmpty(entity1.getUrl())) { | ||||
|         ALog.e(TAG, "下载链接不能为空"); | ||||
|       } else if (checkType && TextUtils.isEmpty(entity1.getDownloadPath())) { | ||||
|         ALog.e(TAG, "保存路径不能为空"); | ||||
|       } else { | ||||
|         b = true; | ||||
|       } | ||||
|     } else if (entity instanceof UTaskWrapper) { | ||||
|       UploadEntity entity1 = ((UTaskWrapper) entity).getEntity(); | ||||
|       if (entity1 == null) { | ||||
|         ALog.e(TAG, "上传实体不能为空"); | ||||
|       } else if (TextUtils.isEmpty(entity1.getFilePath())) { | ||||
|         ALog.e(TAG, "上传文件路径不能为空"); | ||||
|       } else { | ||||
|         b = true; | ||||
|       } | ||||
|     } | ||||
|     return b; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查上传实体是否合法 | ||||
|    */ | ||||
|   private static void checkUploadTaskEntity(UploadEntity entity) { | ||||
|     if (entity == null) { | ||||
|       throw new NullPointerException("上传实体不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getFilePath())) { | ||||
|       throw new IllegalArgumentException("上传文件路径不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getFileName())) { | ||||
|       throw new IllegalArgumentException("上传文件名不能为空"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测下载实体是否合法 | ||||
|    * 合法(true) | ||||
|    * | ||||
|    * @param entity 下载实体 | ||||
|    */ | ||||
|   private static void checkDownloadTaskEntity(DownloadEntity entity) { | ||||
|     if (entity == null) { | ||||
|       throw new NullPointerException("下载实体不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getUrl())) { | ||||
|       throw new IllegalArgumentException("下载链接不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getFileName())) { | ||||
|       throw new NullPointerException("文件名不能为null"); | ||||
|     } else if (TextUtils.isEmpty(entity.getDownloadPath())) { | ||||
|       throw new NullPointerException("文件保存路径不能为null"); | ||||
|     } | ||||
|   } | ||||
| /* | ||||
|  * 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 com.arialyy.aria.core.download.DTaskWrapper; | ||||
| import com.arialyy.aria.core.download.DownloadEntity; | ||||
| import com.arialyy.aria.core.inf.AbsTaskWrapper; | ||||
| import com.arialyy.aria.core.upload.UTaskWrapper; | ||||
| import com.arialyy.aria.core.upload.UploadEntity; | ||||
| import com.arialyy.aria.exception.ParamException; | ||||
| import java.io.File; | ||||
| import java.util.List; | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
| 
 | ||||
| /** | ||||
|  * Created by Lyy on 2016/9/23. | ||||
|  * 检查帮助类 | ||||
|  */ | ||||
| public class CheckUtil { | ||||
|   private static final String TAG = "CheckUtil"; | ||||
| 
 | ||||
|   /** | ||||
|    * 检查ftp上传路径,如果ftp上传路径为空,抛出空指针异常 | ||||
|    * 如果ftp上传路径不是以"ftp"或"sftp",抛出参数异常 | ||||
|    * | ||||
|    * @param ftpUrl ftp上传路径 | ||||
|    */ | ||||
|   public static void checkFtpUploadUrl(String ftpUrl) { | ||||
|     if (TextUtils.isEmpty(ftpUrl)) { | ||||
|       throw new ParamException("ftp上传路径为空"); | ||||
|     } else if (!ftpUrl.startsWith("ftp") || !ftpUrl.startsWith("sftp")) { | ||||
|       throw new ParamException("ftp上传路径无效"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 判空 | ||||
|    */ | ||||
|   public static void checkNull(Object obj) { | ||||
|     if (obj == null) throw new IllegalArgumentException("不能传入空对象"); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查分页数据,需要查询的页数,从1开始,如果page小于1 或 num 小于1,则抛出{@link NullPointerException} | ||||
|    * | ||||
|    * @param page 从1 开始 | ||||
|    * @param num 每页数量 | ||||
|    */ | ||||
|   public static void checkPageParams(int page, int num) { | ||||
|     if (page < 1 || num < 1) throw new NullPointerException("page和num不能小于1"); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查sql的expression是否合法 | ||||
|    */ | ||||
|   public static void checkSqlExpression(String... expression) { | ||||
|     if (expression.length == 0) { | ||||
|       throw new IllegalArgumentException("sql语句表达式不能为null"); | ||||
|     } | ||||
|     if (expression.length == 1) { | ||||
|       throw new IllegalArgumentException("表达式需要写入参数"); | ||||
|     } | ||||
|     String where = expression[0]; | ||||
|     if (!where.contains("?")) { | ||||
|       throw new IllegalArgumentException("请在where语句的'='后编写?"); | ||||
|     } | ||||
|     Pattern pattern = Pattern.compile("\\?"); | ||||
|     Matcher matcher = pattern.matcher(where); | ||||
|     int count = 0; | ||||
|     while (matcher.find()) { | ||||
|       count++; | ||||
|     } | ||||
|     if (count < expression.length - 1) { | ||||
|       throw new IllegalArgumentException("条件语句的?个数不能小于参数个数"); | ||||
|     } | ||||
|     if (count > expression.length - 1) { | ||||
|       throw new IllegalArgumentException("条件语句的?个数不能大于参数个数"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查下载实体 | ||||
|    */ | ||||
|   public static void checkDownloadEntity(DownloadEntity entity) { | ||||
|     checkUrlInvalidThrow(entity.getUrl()); | ||||
|     entity.setUrl(entity.getUrl()); | ||||
|     checkPath(entity.getDownloadPath()); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测下载链接是否为null | ||||
|    */ | ||||
|   public static void checkPath(String path) { | ||||
|     if (TextUtils.isEmpty(path)) { | ||||
|       throw new IllegalArgumentException("保存路径不能为null"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测url是否合法,如果url不合法,将抛异常 | ||||
|    */ | ||||
|   public static void checkUrlInvalidThrow(String url) { | ||||
|     if (TextUtils.isEmpty(url)) { | ||||
|       throw new IllegalArgumentException("url不能为null"); | ||||
|     } else if (!url.startsWith("http") && !url.startsWith("ftp")) { | ||||
|       throw new IllegalArgumentException("url错误"); | ||||
|     } | ||||
|     int index = url.indexOf("://"); | ||||
|     if (index == -1) { | ||||
|       throw new IllegalArgumentException("url不合法"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测url是否合法 | ||||
|    * | ||||
|    * @return {@code true} 合法,{@code false} 非法 | ||||
|    */ | ||||
|   public static boolean checkUrl(String url) { | ||||
|     if (TextUtils.isEmpty(url)) { | ||||
|       ALog.e(TAG, "url不能为null"); | ||||
|       return false; | ||||
|     } else if (!url.startsWith("http") && !url.startsWith("ftp")) { | ||||
|       ALog.e(TAG, "url【" + url + "】错误"); | ||||
|       return false; | ||||
|     } | ||||
|     int index = url.indexOf("://"); | ||||
|     if (index == -1) { | ||||
|       ALog.e(TAG, "url【" + url + "】不合法"); | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测下载链接组是否为null | ||||
|    */ | ||||
|   public static void checkDownloadUrls(List<String> urls) { | ||||
|     if (urls == null || urls.isEmpty()) { | ||||
|       throw new IllegalArgumentException("链接组不能为null"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查下载任务组保存路径 | ||||
|    */ | ||||
|   public static void checkDownloadPaths(List<String> paths) { | ||||
|     if (paths == null || paths.isEmpty()) { | ||||
|       throw new IllegalArgumentException("链接保存路径不能为null"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测上传地址是否为null | ||||
|    */ | ||||
|   public static void checkUploadPath(String uploadPath) { | ||||
|     if (TextUtils.isEmpty(uploadPath)) { | ||||
|       throw new IllegalArgumentException("上传地址不能为null"); | ||||
|     } | ||||
|     File file = new File(uploadPath); | ||||
|     if (!file.exists()) { | ||||
|       throw new IllegalArgumentException("上传文件不存在"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查任务实体 | ||||
|    */ | ||||
|   public static void checkTaskEntity(AbsTaskWrapper entity) { | ||||
|     if (entity instanceof DTaskWrapper) { | ||||
|       checkDownloadTaskEntity(((DTaskWrapper) entity).getEntity()); | ||||
|     } else if (entity instanceof UTaskWrapper) { | ||||
|       checkUploadTaskEntity(((UTaskWrapper) entity).getEntity()); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查命令实体 | ||||
|    * | ||||
|    * @param checkType 删除命令和停止命令不需要检查下载链接和保存路径 | ||||
|    * @return {@code false}实体无效 | ||||
|    */ | ||||
|   public static boolean checkCmdEntity(AbsTaskWrapper entity, boolean checkType) { | ||||
|     boolean b = false; | ||||
|     if (entity instanceof DTaskWrapper) { | ||||
|       DownloadEntity entity1 = ((DTaskWrapper) entity).getEntity(); | ||||
|       if (entity1 == null) { | ||||
|         ALog.e(TAG, "下载实体不能为空"); | ||||
|       } else if (checkType && TextUtils.isEmpty(entity1.getUrl())) { | ||||
|         ALog.e(TAG, "下载链接不能为空"); | ||||
|       } else if (checkType && TextUtils.isEmpty(entity1.getDownloadPath())) { | ||||
|         ALog.e(TAG, "保存路径不能为空"); | ||||
|       } else { | ||||
|         b = true; | ||||
|       } | ||||
|     } else if (entity instanceof UTaskWrapper) { | ||||
|       UploadEntity entity1 = ((UTaskWrapper) entity).getEntity(); | ||||
|       if (entity1 == null) { | ||||
|         ALog.e(TAG, "上传实体不能为空"); | ||||
|       } else if (TextUtils.isEmpty(entity1.getFilePath())) { | ||||
|         ALog.e(TAG, "上传文件路径不能为空"); | ||||
|       } else { | ||||
|         b = true; | ||||
|       } | ||||
|     } | ||||
|     return b; | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检查上传实体是否合法 | ||||
|    */ | ||||
|   private static void checkUploadTaskEntity(UploadEntity entity) { | ||||
|     if (entity == null) { | ||||
|       throw new NullPointerException("上传实体不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getFilePath())) { | ||||
|       throw new IllegalArgumentException("上传文件路径不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getFileName())) { | ||||
|       throw new IllegalArgumentException("上传文件名不能为空"); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * 检测下载实体是否合法 | ||||
|    * 合法(true) | ||||
|    * | ||||
|    * @param entity 下载实体 | ||||
|    */ | ||||
|   private static void checkDownloadTaskEntity(DownloadEntity entity) { | ||||
|     if (entity == null) { | ||||
|       throw new NullPointerException("下载实体不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getUrl())) { | ||||
|       throw new IllegalArgumentException("下载链接不能为空"); | ||||
|     } else if (TextUtils.isEmpty(entity.getFileName())) { | ||||
|       throw new NullPointerException("文件名不能为null"); | ||||
|     } else if (TextUtils.isEmpty(entity.getDownloadPath())) { | ||||
|       throw new NullPointerException("文件保存路径不能为null"); | ||||
|     } | ||||
|   } | ||||
| } | ||||
									
										
											File diff suppressed because it is too large
											Load Diff
										
									
								
							
						| @ -1,161 +1,161 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <aria> | ||||
|   <!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性--> | ||||
| 
 | ||||
|   <!--Aria框架配置--> | ||||
|   <app> | ||||
|     <!--是否使用AriaCrashHandler来捕获异常,异常日志保存在:/mnt/sdcard/Android/data/{package_name}/files/log/--> | ||||
|     <useAriaCrashHandler value="true"/> | ||||
|     <!--设置Aria的日志级别,{@link ALog#LOG_LEVEL_VERBOSE}--> | ||||
|     <logLevel value="2"/> | ||||
|     <!-- 是否检查网络 true: 检查网络,false: 不检查网络--> | ||||
|     <netCheck value="false"/> | ||||
|     <!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 --> | ||||
|     <!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html --> | ||||
|     <useBroadcast value="true"/> | ||||
|     <!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调--> | ||||
|     <notNetRetry value="true"/> | ||||
|   </app> | ||||
| 
 | ||||
| 
 | ||||
|   <!--普通下载任务--> | ||||
|   <download> | ||||
| 
 | ||||
|     <!--设置任务最大下载速度,0表示不限速,单位为:kb--> | ||||
|     <maxSpeed value="128"/> | ||||
| 
 | ||||
|     <!-- | ||||
|       多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 | ||||
|       注意: | ||||
|         1、使用分块模式,在读写性能底下的手机上,合并文件需要的时间会更加长; | ||||
|         2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; | ||||
|         3、只对新的多线程下载任务有效 | ||||
|         4、只对多线程的任务有效 | ||||
|     --> | ||||
|     <useBlock value="true"/> | ||||
| 
 | ||||
|     <!--设置下载线程数,下载线程数不能小于1 | ||||
|       注意: | ||||
|       1、线程下载数改变后,新的下载任务才会生效; | ||||
|       2、如果任务大小小于1m,该设置不会生效; | ||||
|       3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; | ||||
|          对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式; | ||||
|     --> | ||||
|     <threadNum value="3"/> | ||||
| 
 | ||||
|     <!--设置下载队列最大任务数, 默认为2--> | ||||
|     <maxTaskNum value="1"/> | ||||
| 
 | ||||
|     <!--设置下载失败,重试次数,默认为10--> | ||||
|     <reTryNum value="1"/> | ||||
| 
 | ||||
|     <!--设置重试间隔,单位为毫秒,默认2000毫秒--> | ||||
|     <reTryInterval value="5000"/> | ||||
| 
 | ||||
|     <!--设置url连接超时时间,单位为毫秒,默认5000毫秒--> | ||||
|     <connectTimeOut value="5000"/> | ||||
| 
 | ||||
|     <!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> | ||||
|     <iOTimeOut value="10000"/> | ||||
| 
 | ||||
|     <!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢--> | ||||
|     <buffSize value="8192"/> | ||||
| 
 | ||||
|     <!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名--> | ||||
|     <ca name="" path=""/> | ||||
| 
 | ||||
|     <!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度--> | ||||
|     <convertSpeed value="true"/> | ||||
| 
 | ||||
|     <!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait--> | ||||
|     <queueMod value="wait"/> | ||||
| 
 | ||||
|     <!--进度更新更新间隔,默认1000毫秒--> | ||||
|     <updateInterval value="1000"/> | ||||
| 
 | ||||
|   </download> | ||||
| 
 | ||||
|   <!--普通上传任务--> | ||||
|   <upload> | ||||
|     <!--设置任务最大上传速度,0表示不限速,单位为:kb--> | ||||
|     <maxSpeed value="0"/> | ||||
| 
 | ||||
|     <!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> | ||||
|     <iOTimeOut value="10000"/> | ||||
| 
 | ||||
|     <!--设置写文件buff大小,该数值大小不能小于2048,数值变小,速度会变慢--> | ||||
|     <buffSize value="8192"/> | ||||
| 
 | ||||
|     <!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度--> | ||||
|     <convertSpeed value="true"/> | ||||
| 
 | ||||
|     <!--设置上传队列最大任务数, 默认为2--> | ||||
|     <maxTaskNum value="2"/> | ||||
| 
 | ||||
|     <!--设置上传失败,重试次数,默认为10--> | ||||
|     <reTryNum value="3"/> | ||||
| 
 | ||||
|     <!--设置重试间隔,单位为毫秒--> | ||||
|     <reTryInterval value="2000"/> | ||||
| 
 | ||||
|     <!--设置url连接超时时间,单位为毫秒,默认5000毫秒--> | ||||
|     <connectTimeOut value="5000"/> | ||||
| 
 | ||||
|     <!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait--> | ||||
|     <queueMod value="wait"/> | ||||
| 
 | ||||
|     <!--进度更新更新间隔,默认1000毫秒--> | ||||
|     <updateInterval value="1000"/> | ||||
| 
 | ||||
|   </upload> | ||||
| 
 | ||||
|   <!-- 下载类组合任务 --> | ||||
|   <dGroup> | ||||
| 
 | ||||
|     <!--组合任务下载队列最大任务数, 默认为2--> | ||||
|     <maxTaskNum value="1"/> | ||||
| 
 | ||||
|     <!--设置下载失败,重试次数,默认为10--> | ||||
|     <reTryNum value="1"/> | ||||
| 
 | ||||
|     <!--设置重试间隔,单位为毫秒,默认2000毫秒--> | ||||
|     <reTryInterval value="5000"/> | ||||
| 
 | ||||
|     <!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait--> | ||||
|     <queueMod value="wait"/> | ||||
| 
 | ||||
|     <!--进度更新更新间隔,默认1000毫秒--> | ||||
|     <updateInterval value="1000"/> | ||||
| 
 | ||||
| 
 | ||||
|     <!-- =============================以下为子任务的配置====================================--> | ||||
| 
 | ||||
|     <!--能同时下载的子任务最大任务数,默认3--> | ||||
|     <subMaxTaskNum value="1"/> | ||||
| 
 | ||||
|     <!--子任务下载失败时的重试次数,默认为5--> | ||||
|     <subReTryNum value="5"/> | ||||
| 
 | ||||
|     <!--子任务下载失败时的重试间隔,单位为毫秒,默认2000毫秒--> | ||||
|     <subReTryInterval value="5000"/> | ||||
| 
 | ||||
|     <!--子任务url连接超时时间,单位为毫秒,默认5000毫秒--> | ||||
|     <connectTimeOut value="5000"/> | ||||
| 
 | ||||
|     <!--子任务IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> | ||||
|     <iOTimeOut value="10000"/> | ||||
| 
 | ||||
|     <!--子任务写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢--> | ||||
|     <buffSize value="8192"/> | ||||
| 
 | ||||
|     <!--子任务 https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名--> | ||||
|     <ca name="" path=""/> | ||||
| 
 | ||||
|     <!--子任务是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度--> | ||||
|     <convertSpeed value="true"/> | ||||
| 
 | ||||
|     <!--子任务的最大下载速度,0表示不限速,单位为:kb; --> | ||||
|     <maxSpeed value="0"/> | ||||
| 
 | ||||
|   </dGroup> | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <aria> | ||||
|   <!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性--> | ||||
| 
 | ||||
|   <!--Aria框架配置--> | ||||
|   <app> | ||||
|     <!--是否使用AriaCrashHandler来捕获异常,异常日志保存在:/mnt/sdcard/Android/data/{package_name}/files/log/--> | ||||
|     <useAriaCrashHandler value="true"/> | ||||
|     <!--设置Aria的日志级别,{@link ALog#LOG_LEVEL_VERBOSE}--> | ||||
|     <logLevel value="2"/> | ||||
|     <!-- 是否检查网络 true: 检查网络,false: 不检查网络--> | ||||
|     <netCheck value="false"/> | ||||
|     <!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 --> | ||||
|     <!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html --> | ||||
|     <useBroadcast value="true"/> | ||||
|     <!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调--> | ||||
|     <notNetRetry value="true"/> | ||||
|   </app> | ||||
| 
 | ||||
| 
 | ||||
|   <!--普通下载任务--> | ||||
|   <download> | ||||
| 
 | ||||
|     <!--设置任务最大下载速度,0表示不限速,单位为:kb--> | ||||
|     <maxSpeed value="128"/> | ||||
| 
 | ||||
|     <!-- | ||||
|       多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用 | ||||
|       注意: | ||||
|         1、使用分块模式,在I/O性能底下的手机上,合并文件需要的时间会更加长; | ||||
|         2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间; | ||||
|         3、只对新的多线程下载任务有效 | ||||
|         4、只对多线程的任务有效 | ||||
|     --> | ||||
|     <useBlock value="true"/> | ||||
| 
 | ||||
|     <!--设置下载线程数,下载线程数不能小于1 | ||||
|       注意: | ||||
|       1、线程下载数改变后,新的下载任务才会生效; | ||||
|       2、如果任务大小小于1m,该设置不会生效; | ||||
|       3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间; | ||||
|          对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式; | ||||
|     --> | ||||
|     <threadNum value="1"/> | ||||
| 
 | ||||
|     <!--设置下载队列最大任务数, 默认为2--> | ||||
|     <maxTaskNum value="1"/> | ||||
| 
 | ||||
|     <!--设置下载失败,重试次数,默认为10--> | ||||
|     <reTryNum value="1"/> | ||||
| 
 | ||||
|     <!--设置重试间隔,单位为毫秒,默认2000毫秒--> | ||||
|     <reTryInterval value="5000"/> | ||||
| 
 | ||||
|     <!--设置url连接超时时间,单位为毫秒,默认5000毫秒--> | ||||
|     <connectTimeOut value="5000"/> | ||||
| 
 | ||||
|     <!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> | ||||
|     <iOTimeOut value="10000"/> | ||||
| 
 | ||||
|     <!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢--> | ||||
|     <buffSize value="8192"/> | ||||
| 
 | ||||
|     <!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名--> | ||||
|     <ca name="" path=""/> | ||||
| 
 | ||||
|     <!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度--> | ||||
|     <convertSpeed value="true"/> | ||||
| 
 | ||||
|     <!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait--> | ||||
|     <queueMod value="wait"/> | ||||
| 
 | ||||
|     <!--进度更新更新间隔,默认1000毫秒--> | ||||
|     <updateInterval value="1000"/> | ||||
| 
 | ||||
|   </download> | ||||
| 
 | ||||
|   <!--普通上传任务--> | ||||
|   <upload> | ||||
|     <!--设置任务最大上传速度,0表示不限速,单位为:kb--> | ||||
|     <maxSpeed value="0"/> | ||||
| 
 | ||||
|     <!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> | ||||
|     <iOTimeOut value="10000"/> | ||||
| 
 | ||||
|     <!--设置写文件buff大小,该数值大小不能小于2048,数值变小,速度会变慢--> | ||||
|     <buffSize value="8192"/> | ||||
| 
 | ||||
|     <!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度--> | ||||
|     <convertSpeed value="true"/> | ||||
| 
 | ||||
|     <!--设置上传队列最大任务数, 默认为2--> | ||||
|     <maxTaskNum value="2"/> | ||||
| 
 | ||||
|     <!--设置上传失败,重试次数,默认为10--> | ||||
|     <reTryNum value="3"/> | ||||
| 
 | ||||
|     <!--设置重试间隔,单位为毫秒--> | ||||
|     <reTryInterval value="2000"/> | ||||
| 
 | ||||
|     <!--设置url连接超时时间,单位为毫秒,默认5000毫秒--> | ||||
|     <connectTimeOut value="5000"/> | ||||
| 
 | ||||
|     <!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait--> | ||||
|     <queueMod value="wait"/> | ||||
| 
 | ||||
|     <!--进度更新更新间隔,默认1000毫秒--> | ||||
|     <updateInterval value="1000"/> | ||||
| 
 | ||||
|   </upload> | ||||
| 
 | ||||
|   <!-- 下载类组合任务 --> | ||||
|   <dGroup> | ||||
| 
 | ||||
|     <!--组合任务下载队列最大任务数, 默认为2--> | ||||
|     <maxTaskNum value="1"/> | ||||
| 
 | ||||
|     <!--设置下载失败,重试次数,默认为10--> | ||||
|     <reTryNum value="1"/> | ||||
| 
 | ||||
|     <!--设置重试间隔,单位为毫秒,默认2000毫秒--> | ||||
|     <reTryInterval value="5000"/> | ||||
| 
 | ||||
|     <!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait--> | ||||
|     <queueMod value="wait"/> | ||||
| 
 | ||||
|     <!--进度更新更新间隔,默认1000毫秒--> | ||||
|     <updateInterval value="1000"/> | ||||
| 
 | ||||
| 
 | ||||
|     <!-- =============================以下为子任务的配置====================================--> | ||||
| 
 | ||||
|     <!--能同时下载的子任务最大任务数,默认3--> | ||||
|     <subMaxTaskNum value="1"/> | ||||
| 
 | ||||
|     <!--子任务下载失败时的重试次数,默认为5--> | ||||
|     <subReTryNum value="5"/> | ||||
| 
 | ||||
|     <!--子任务下载失败时的重试间隔,单位为毫秒,默认2000毫秒--> | ||||
|     <subReTryInterval value="5000"/> | ||||
| 
 | ||||
|     <!--子任务url连接超时时间,单位为毫秒,默认5000毫秒--> | ||||
|     <connectTimeOut value="5000"/> | ||||
| 
 | ||||
|     <!--子任务IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒--> | ||||
|     <iOTimeOut value="10000"/> | ||||
| 
 | ||||
|     <!--子任务写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢--> | ||||
|     <buffSize value="8192"/> | ||||
| 
 | ||||
|     <!--子任务 https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名--> | ||||
|     <ca name="" path=""/> | ||||
| 
 | ||||
|     <!--子任务是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度--> | ||||
|     <convertSpeed value="true"/> | ||||
| 
 | ||||
|     <!--子任务的最大下载速度,0表示不限速,单位为:kb; --> | ||||
|     <maxSpeed value="0"/> | ||||
| 
 | ||||
|   </dGroup> | ||||
| </aria> | ||||
| @ -1,80 +1,80 @@ | ||||
| package com.arialyy.simple.core.test; | ||||
| 
 | ||||
| import android.os.Environment; | ||||
| import android.view.View; | ||||
| import com.arialyy.aria.core.Aria; | ||||
| import com.arialyy.aria.core.common.QueueMod; | ||||
| import com.arialyy.simple.R; | ||||
| import com.arialyy.simple.base.BaseActivity; | ||||
| import com.arialyy.simple.databinding.TestActivityMultiBinding; | ||||
| 
 | ||||
| /** | ||||
|  * Created by AriaL on 2017/6/15. | ||||
|  */ | ||||
| 
 | ||||
| public class TestMutilTaskSysDownload extends BaseActivity<TestActivityMultiBinding> { | ||||
| 
 | ||||
|   @Override protected int setLayoutId() { | ||||
|     return R.layout.test_activity_multi; | ||||
|   } | ||||
| 
 | ||||
|   public void onClick(View view) { | ||||
|     String baseUrl = "http://file.bmob.cn/"; | ||||
|     String[] urlArray = { | ||||
|         "M02/3B/A4/oYYBAFaOeUSAc1QiAAFTbmA7AHs052.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeUaAfYC-AAFD8zf9NXc879.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeUuAOxhnAACSdmbqSac702.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeU2AFAIGAAFICximvXc924.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVCAPWMQAAFm2KWCq_E721.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVOAbiv9AAFfCTTgr94948.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVaAMR3tAAFf3yTuuCM577.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVmACEWhAAEt72ecbpg468.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVyAHHt4AAFg9e9bRio507.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeV-AClYXAAESLGY0gag424.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWKAA7N0AAF3omYOJUI703.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWWAD2lrAAFN7eRFxBs575.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWiAdCVEAAFg4273Dus313.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWyAJDm5AAF8JVoGVb0705.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeW-AUoA8AAGjKiHkXUo181.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeXKABIamAAFU7J7vraE265.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeXaAW09jAAFf37qdwDA457.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeXmAWmS7AAFtLNpWjgo967.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeX2AQf9cAAF2fhwS2UE145.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYCAKGnLAAFVAzks-qU937.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYOAMODNAAF6HjTTMq4819.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYeAbn8uAAFLSQLw48Q042.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYqAMJThAAFtrNe4UNM047.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeY2AbnQvAAFNSXWn0Dc026.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZCAIsr0AAFHZFEVhPc682.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZOAGvITAAFqPmfcc9c471.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZaATvjbAAFHDmALnhE003.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZmAJPuVAAFfPJC2wsE319.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZyAXtAmAAFfArJNwtM371.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZ-AGZN0AAFgqwYYCS8004.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeaOAbbrGAAFcq59JjUo205.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeaSAdFyoAACaxVxgUJA092.jpg" | ||||
|     }; | ||||
|     int maxNum = Aria.get(this).getDownloadConfig().getMaxTaskNum(); | ||||
|     Aria.get(this).setDownloadQueueMod(QueueMod.NOW); | ||||
|     for (int i = 0; i < urlArray.length; i++) { | ||||
|       Aria.download(this) | ||||
|           .load(baseUrl + urlArray[i]) | ||||
|           .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") | ||||
|           //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
 | ||||
|           .start(); | ||||
|       //if (i < maxNum) {
 | ||||
|       //  Aria.download(this)
 | ||||
|       //      .load(baseUrl + urlArray[i])
 | ||||
|       //      .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
 | ||||
|       //      //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
 | ||||
|       //      .start();
 | ||||
|       //} else {
 | ||||
|       //  Aria.download(this)
 | ||||
|       //      .load(baseUrl + urlArray[i])
 | ||||
|       //      .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
 | ||||
|       //      //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
 | ||||
|       //      .add();
 | ||||
|       //}
 | ||||
|     } | ||||
|   } | ||||
| } | ||||
| package com.arialyy.simple.core.test; | ||||
| 
 | ||||
| import android.os.Environment; | ||||
| import android.view.View; | ||||
| import com.arialyy.aria.core.Aria; | ||||
| import com.arialyy.aria.core.common.QueueMod; | ||||
| import com.arialyy.simple.R; | ||||
| import com.arialyy.simple.base.BaseActivity; | ||||
| import com.arialyy.simple.databinding.TestActivityMultiBinding; | ||||
| 
 | ||||
| /** | ||||
|  * Created by AriaL on 2017/6/15. | ||||
|  */ | ||||
| 
 | ||||
| public class TestMutilTaskSysDownload extends BaseActivity<TestActivityMultiBinding> { | ||||
| 
 | ||||
|   @Override protected int setLayoutId() { | ||||
|     return R.layout.test_activity_multi; | ||||
|   } | ||||
| 
 | ||||
|   public void onClick(View view) { | ||||
|     String baseUrl = "http://file.bmob.cn/"; | ||||
|     String[] urlArray = { | ||||
|         "M02/3B/A4/oYYBAFaOeUSAc1QiAAFTbmA7AHs052.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeUaAfYC-AAFD8zf9NXc879.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeUuAOxhnAACSdmbqSac702.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeU2AFAIGAAFICximvXc924.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVCAPWMQAAFm2KWCq_E721.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVOAbiv9AAFfCTTgr94948.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVaAMR3tAAFf3yTuuCM577.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVmACEWhAAEt72ecbpg468.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeVyAHHt4AAFg9e9bRio507.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeV-AClYXAAESLGY0gag424.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWKAA7N0AAF3omYOJUI703.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWWAD2lrAAFN7eRFxBs575.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWiAdCVEAAFg4273Dus313.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeWyAJDm5AAF8JVoGVb0705.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeW-AUoA8AAGjKiHkXUo181.jpg", | ||||
|         "M02/3B/A4/oYYBAFaOeXKABIamAAFU7J7vraE265.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeXaAW09jAAFf37qdwDA457.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeXmAWmS7AAFtLNpWjgo967.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeX2AQf9cAAF2fhwS2UE145.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYCAKGnLAAFVAzks-qU937.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYOAMODNAAF6HjTTMq4819.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYeAbn8uAAFLSQLw48Q042.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeYqAMJThAAFtrNe4UNM047.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeY2AbnQvAAFNSXWn0Dc026.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZCAIsr0AAFHZFEVhPc682.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZOAGvITAAFqPmfcc9c471.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZaATvjbAAFHDmALnhE003.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZmAJPuVAAFfPJC2wsE319.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZyAXtAmAAFfArJNwtM371.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeZ-AGZN0AAFgqwYYCS8004.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeaOAbbrGAAFcq59JjUo205.jpg", | ||||
|         "M02/3B/A5/oYYBAFaOeaSAdFyoAACaxVxgUJA092.jpg" | ||||
|     }; | ||||
|     int maxNum = Aria.get(this).getDownloadConfig().getMaxTaskNum(); | ||||
|     Aria.get(this).setDownloadQueueMod(QueueMod.NOW); | ||||
|     for (int i = 0; i < urlArray.length; i++) { | ||||
|       Aria.download(this) | ||||
|           .load(baseUrl + urlArray[i]) | ||||
|           .setFilePath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg") | ||||
|           //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
 | ||||
|           .start(); | ||||
|       //if (i < maxNum) {
 | ||||
|       //  Aria.download(this)
 | ||||
|       //      .load(baseUrl + urlArray[i])
 | ||||
|       //      .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
 | ||||
|       //      //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
 | ||||
|       //      .start();
 | ||||
|       //} else {
 | ||||
|       //  Aria.download(this)
 | ||||
|       //      .load(baseUrl + urlArray[i])
 | ||||
|       //      .setDownloadPath(Environment.getExternalStorageDirectory() + "/test/" + i + ".jpg")
 | ||||
|       //      //.addHeader("Accept-Encoding", "gzip,deflate,sdcn")
 | ||||
|       //      .add();
 | ||||
|       //}
 | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,113 +1,113 @@ | ||||
| /* | ||||
|  * 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.core.upload; | ||||
| 
 | ||||
| import android.os.Bundle; | ||||
| import android.util.Log; | ||||
| import android.view.View; | ||||
| import com.arialyy.annotations.Upload; | ||||
| import com.arialyy.aria.core.Aria; | ||||
| import com.arialyy.aria.core.upload.UploadEntity; | ||||
| import com.arialyy.aria.core.upload.UploadTask; | ||||
| import com.arialyy.aria.util.CommonUtil; | ||||
| import com.arialyy.frame.util.FileUtil; | ||||
| import com.arialyy.frame.util.show.T; | ||||
| import com.arialyy.simple.R; | ||||
| import com.arialyy.simple.base.BaseActivity; | ||||
| import com.arialyy.simple.databinding.ActivityFtpUploadBinding; | ||||
| import java.io.File; | ||||
| 
 | ||||
| /** | ||||
|  * Created by lyy on 2017/7/28. Ftp 文件上传demo | ||||
|  */ | ||||
| public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> { | ||||
|   private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar"; | ||||
|   private final String URL = "ftp://9.9.9.50:21/aa/你好"; | ||||
| 
 | ||||
|   @Override protected void init(Bundle savedInstanceState) { | ||||
|     setTile("D_FTP 文件上传"); | ||||
|     super.init(savedInstanceState); | ||||
|     Aria.upload(this).register(); | ||||
|     UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH); | ||||
|     if (entity != null) { | ||||
|       getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize())); | ||||
|       getBinding().setProgress(entity.isComplete() ? 100 | ||||
|           : (int) (entity.getCurrentProgress() * 100 / entity.getFileSize())); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @Override protected int setLayoutId() { | ||||
|     return R.layout.activity_ftp_upload; | ||||
|   } | ||||
| 
 | ||||
|   public void onClick(View view) { | ||||
|     switch (view.getId()) { | ||||
|       case R.id.start: | ||||
|         Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").start(); | ||||
|         break; | ||||
|       case R.id.stop: | ||||
|         Aria.upload(this).loadFtp(FILE_PATH).stop(); | ||||
|         break; | ||||
|       case R.id.cancel: | ||||
|         Aria.upload(this).loadFtp(FILE_PATH).cancel(); | ||||
|         break; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onWait void onWait(UploadTask task) { | ||||
|     Log.d(TAG, task.getTaskName() + "_wait"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onPre public void onPre(UploadTask task) { | ||||
|     getBinding().setFileSize(task.getConvertFileSize()); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskStart public void taskStart(UploadTask task) { | ||||
|     Log.d(TAG, "开始上传,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskResume public void taskResume(UploadTask task) { | ||||
|     Log.d(TAG, "恢复上传"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskStop public void taskStop(UploadTask task) { | ||||
|     getBinding().setSpeed(""); | ||||
|     Log.d(TAG, "停止上传"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskCancel public void taskCancel(UploadTask task) { | ||||
|     getBinding().setSpeed(""); | ||||
|     getBinding().setFileSize(""); | ||||
|     getBinding().setProgress(0); | ||||
|     Log.d(TAG, "删除任务"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskFail public void taskFail(UploadTask task) { | ||||
|     Log.d(TAG, "上传失败"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskRunning public void taskRunning(UploadTask task) { | ||||
|     Log.d(TAG, "PP = " + task.getPercent()); | ||||
|     getBinding().setProgress(task.getPercent()); | ||||
|     getBinding().setSpeed(task.getConvertSpeed()); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskComplete public void taskComplete(UploadTask task) { | ||||
|     getBinding().setProgress(100); | ||||
|     getBinding().setSpeed(""); | ||||
|     T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成"); | ||||
|   } | ||||
| } | ||||
| /* | ||||
|  * 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.core.upload; | ||||
| 
 | ||||
| import android.os.Bundle; | ||||
| import android.util.Log; | ||||
| import android.view.View; | ||||
| import com.arialyy.annotations.Upload; | ||||
| import com.arialyy.aria.core.Aria; | ||||
| import com.arialyy.aria.core.upload.UploadEntity; | ||||
| import com.arialyy.aria.core.upload.UploadTask; | ||||
| import com.arialyy.aria.util.CommonUtil; | ||||
| import com.arialyy.frame.util.FileUtil; | ||||
| import com.arialyy.frame.util.show.T; | ||||
| import com.arialyy.simple.R; | ||||
| import com.arialyy.simple.base.BaseActivity; | ||||
| import com.arialyy.simple.databinding.ActivityFtpUploadBinding; | ||||
| import java.io.File; | ||||
| 
 | ||||
| /** | ||||
|  * Created by lyy on 2017/7/28. Ftp 文件上传demo | ||||
|  */ | ||||
| public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> { | ||||
|   private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar"; | ||||
|   private final String URL = "ftp://9.9.9.205:2121/aa/你好"; | ||||
| 
 | ||||
|   @Override protected void init(Bundle savedInstanceState) { | ||||
|     setTile("D_FTP 文件上传"); | ||||
|     super.init(savedInstanceState); | ||||
|     Aria.upload(this).register(); | ||||
|     UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH); | ||||
|     if (entity != null) { | ||||
|       getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize())); | ||||
|       getBinding().setProgress(entity.isComplete() ? 100 | ||||
|           : (int) (entity.getCurrentProgress() * 100 / entity.getFileSize())); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @Override protected int setLayoutId() { | ||||
|     return R.layout.activity_ftp_upload; | ||||
|   } | ||||
| 
 | ||||
|   public void onClick(View view) { | ||||
|     switch (view.getId()) { | ||||
|       case R.id.start: | ||||
|         Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").start(); | ||||
|         break; | ||||
|       case R.id.stop: | ||||
|         Aria.upload(this).loadFtp(FILE_PATH).stop(); | ||||
|         break; | ||||
|       case R.id.cancel: | ||||
|         Aria.upload(this).loadFtp(FILE_PATH).cancel(); | ||||
|         break; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onWait void onWait(UploadTask task) { | ||||
|     Log.d(TAG, task.getTaskName() + "_wait"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onPre public void onPre(UploadTask task) { | ||||
|     getBinding().setFileSize(task.getConvertFileSize()); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskStart public void taskStart(UploadTask task) { | ||||
|     Log.d(TAG, "开始上传,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskResume public void taskResume(UploadTask task) { | ||||
|     Log.d(TAG, "恢复上传"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskStop public void taskStop(UploadTask task) { | ||||
|     getBinding().setSpeed(""); | ||||
|     Log.d(TAG, "停止上传"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskCancel public void taskCancel(UploadTask task) { | ||||
|     getBinding().setSpeed(""); | ||||
|     getBinding().setFileSize(""); | ||||
|     getBinding().setProgress(0); | ||||
|     Log.d(TAG, "删除任务"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskFail public void taskFail(UploadTask task) { | ||||
|     Log.d(TAG, "上传失败"); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskRunning public void taskRunning(UploadTask task) { | ||||
|     Log.d(TAG, "PP = " + task.getPercent()); | ||||
|     getBinding().setProgress(task.getPercent()); | ||||
|     getBinding().setSpeed(task.getConvertSpeed()); | ||||
|   } | ||||
| 
 | ||||
|   @Upload.onTaskComplete public void taskComplete(UploadTask task) { | ||||
|     getBinding().setProgress(100); | ||||
|     getBinding().setSpeed(""); | ||||
|     T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成"); | ||||
|   } | ||||
| } | ||||
|  | ||||
					Loading…
					
					
				
		Reference in new issue