Skip to content
Permalink
Browse files

增加非静态的成员类警告提示

  • Loading branch information...
AriaLyy committed Oct 16, 2019
1 parent ce408c0 commit df310b7fbea481d3b5901718958ef53fa3872c7e
@@ -23,12 +23,12 @@
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CommonUtil;

public abstract class BaseDelegate<TARGET extends AbsTarget> {
public abstract class BaseOption<TARGET extends AbsTarget> {
protected final String TAG;
protected TARGET mTarget;
protected AbsTaskWrapper mWrapper;

public BaseDelegate(TARGET target, AbsTaskWrapper wrapper) {
public BaseOption(TARGET target, AbsTaskWrapper wrapper) {
TAG = CommonUtil.getClassName(getClass());
mTarget = target;
mWrapper = wrapper;
@@ -28,7 +28,7 @@
/**
* D_FTP SSL/TSL 参数委托
*/
public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class FTPSDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {

private FtpUrlEntity mUrlEntity;

@@ -28,7 +28,7 @@
/**
* Created by laoyuyu on 2018/3/9.
*/
public class FtpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class FtpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private static final String TAG = "FtpDelegate";

public FtpDelegate(TARGET target, AbsTaskWrapper wrapper) {
@@ -18,19 +18,19 @@
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import java.net.Proxy;
import java.util.HashMap;
import java.util.Map;

/**
* HTTP协议处理
* HTTP任务设置
*/
public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {

private Map<String, String> params;
private Map<String, String> headers;
@@ -16,7 +16,7 @@
package com.arialyy.aria.core.download.m3u8;

import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IOptionConstant;
@@ -25,12 +25,13 @@
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.ComponentUtil;

/**
* m3u8 委托
*/
public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class M3U8Delegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private DTaskWrapper mTaskWrapper;

public M3U8Delegate(TARGET target, AbsTaskWrapper wrapper) {
@@ -67,6 +68,7 @@ public M3U8Delegate(TARGET target, AbsTaskWrapper wrapper) {
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setMergeHandler(ITsMergeHandler handler) {
CheckUtil.checkMemberClass(handler.getClass());
mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.mergeHandler, handler);
return this;
}
@@ -79,6 +81,7 @@ public M3U8Delegate(TARGET target, AbsTaskWrapper wrapper) {
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setTsUrlConvert(IVodTsUrlConverter converter) {
CheckUtil.checkMemberClass(converter.getClass());
mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.vodUrlConverter, converter);
return this;
}
@@ -102,6 +105,7 @@ public M3U8Delegate(TARGET target, AbsTaskWrapper wrapper) {
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setBandWidthUrlConverter(IBandWidthUrlConverter converter) {
CheckUtil.checkMemberClass(converter.getClass());
mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.bandWidthUrlConverter, converter);
return this;
}
@@ -16,19 +16,20 @@
package com.arialyy.aria.core.download.m3u8;

import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;

/**
* m3u8直播参数设置
*/
public class M3U8LiveDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class M3U8LiveDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {

M3U8LiveDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
@@ -43,6 +44,7 @@
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8LiveDelegate<TARGET> setLiveTsUrlConvert(ILiveTsUrlConverter converter) {
CheckUtil.checkMemberClass(converter.getClass());
((DTaskWrapper) getTaskWrapper()).getM3U8Params()
.setObjs(IOptionConstant.liveTsUrlConverter, converter);
return this;
@@ -16,7 +16,7 @@
package com.arialyy.aria.core.download.m3u8;

import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.event.EventMsgUtil;
@@ -30,7 +30,7 @@
/**
* m3u8点播文件参数设置
*/
public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private DTaskWrapper mTaskWrapper;

M3U8VodDelegate(TARGET target, AbsTaskWrapper wrapper) {
@@ -17,14 +17,15 @@

import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import java.util.List;

/**
@@ -151,6 +152,7 @@ public GroupBuilderTarget setFileLenAdapter(IHttpFileLenAdapter adapter) {
if (adapter == null) {
throw new IllegalArgumentException("adapter为空");
}
CheckUtil.checkMemberClass(adapter.getClass());
getTaskWrapper().getOptionParams().setObjs(IOptionConstant.fileLenAdapter, adapter);
return this;
}
@@ -24,6 +24,7 @@
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CheckUtil;

public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {

@@ -95,7 +96,7 @@ public HttpBuilderTarget setFileLenAdapter(IHttpFileLenAdapter adapter) {
if (adapter == null) {
throw new IllegalArgumentException("adapter为空");
}

CheckUtil.checkMemberClass(adapter.getClass());
getTaskWrapper().getOptionParams().setObjs(IOptionConstant.fileLenAdapter, adapter);
return this;
}
@@ -17,7 +17,7 @@

import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
@@ -28,7 +28,7 @@
* @Author aria
* @Date 2019-09-06
*/
public class TcpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
public class TcpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {

private TcpTaskConfig mTcpConfig;

@@ -22,6 +22,7 @@
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CheckUtil;

/**
* Created by Aria.Lao on 2017/7/27.
@@ -52,6 +53,7 @@ public FtpBuilderTarget setUploadUrl(String tempUrl) {
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpBuilderTarget setUploadInterceptor(@NonNull IFtpUploadInterceptor uploadInterceptor) {
CheckUtil.checkMemberClass(uploadInterceptor.getClass());
return mConfigHandler.setUploadInterceptor(uploadInterceptor);
}

@@ -27,7 +27,7 @@
* @Date 2019-09-19
*/
public class HttpULoaderUtil extends AbsNormalLoaderUtil {
protected HttpULoaderUtil(AbsTaskWrapper wrapper, IEventListener listener) {
public HttpULoaderUtil(AbsTaskWrapper wrapper, IEventListener listener) {
super(wrapper, listener);
wrapper.generateTaskOption(HttpTaskOption.class);
}
@@ -19,11 +19,11 @@
import android.text.TextUtils;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.ParamException;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import java.io.File;
import java.lang.reflect.Modifier;
import java.util.List;

/**
@@ -34,26 +34,15 @@
private static final String TAG = "CheckUtil";

/**
* 检查ftp上传路径,如果ftp上传路径为空,抛出空指针异常
* 如果ftp上传路径不是以"ftp"或"sftp",抛出参数异常
*
* @param ftpUrl ftp上传路径
* 检查成员类是否是静态和public
*/
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 checkMemberClass(Class clazz) {
int modifiers = clazz.getModifiers();
if (!clazz.isMemberClass() || !Modifier.isStatic(modifiers) || Modifier.isPrivate(modifiers)) {
ALog.e(TAG, "为了放置内存泄漏,请使用静态的成员类(public static class xxx)或文件类(A.java)");
}
}

/**
* 判空
*/
public static void checkNull(Object obj) {
if (obj == null) throw new IllegalArgumentException("不能传入空对象");
}

/**
* 检查分页数据,需要查询的页数,从1开始,如果page小于1 或 num 小于1,则抛出{@link NullPointerException}
*
@@ -64,15 +53,6 @@ public static void checkPageParams(int page, int num) {
if (page < 1 || num < 1) throw new NullPointerException("page和num不能小于1");
}

/**
* 检查下载实体
*/
public static void checkDownloadEntity(DownloadEntity entity) {
checkUrlInvalidThrow(entity.getUrl());
entity.setUrl(entity.getUrl());
checkPath(entity.getDownloadPath());
}

/**
* 检测下载链接是否为null
*/
@@ -150,15 +130,6 @@ public static void checkDownloadUrls(List<String> urls) {
}
}

/**
* 检查下载任务组保存路径
*/
public static void checkDownloadPaths(List<String> paths) {
if (paths == null || paths.isEmpty()) {
throw new IllegalArgumentException("链接保存路径不能为null");
}
}

/**
* 检测上传地址是否为null
*/
@@ -31,11 +31,11 @@
import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@@ -291,18 +291,7 @@ private void startD() {
.load(mUrl)
.useServerFileName(true)
.setFilePath(mFilePath, true)
.setFileLenAdapter(new IHttpFileLenAdapter() {
@Override public long handleFileLen(Map<String, List<String>> headers) {

List<String> sLength = headers.get("Content-Length");
if (sLength == null || sLength.isEmpty()) {
return -1;
}
String temp = sLength.get(0);

return Long.parseLong(temp);
}
})
.setFileLenAdapter(new FileLenAdapter())
.option()
.addHeader("1", "@")
.controller(ControllerType.CREATE_CONTROLLER)
@@ -327,4 +316,17 @@ protected void onStop() {
mModule.updateFilePath(this, String.valueOf(data));
}
}

static class FileLenAdapter implements IHttpFileLenAdapter {
@Override public long handleFileLen(Map<String, List<String>> headers) {

List<String> sLength = headers.get("Content-Length");
if (sLength == null || sLength.isEmpty()) {
return -1;
}
String temp = sLength.get(0);

return Long.parseLong(temp);
}
}
}

0 comments on commit df310b7

Please sign in to comment.
You can’t perform that action at this time.