添加设备id 分批执行任务
parent
7a6f804ab5
commit
9754183e1a
@ -0,0 +1,187 @@
|
||||
package com.baiyee.adcallback.tools;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class TxtUtils {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TxtUtils.class);
|
||||
/**
|
||||
* txt解析方法
|
||||
* @param inputStream 文件流
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> txtParseList(InputStream inputStream) throws IOException {
|
||||
List<String> list = new ArrayList<>();
|
||||
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
|
||||
try {
|
||||
String count;
|
||||
while((count = d.readLine()) != null){
|
||||
String u = count.toUpperCase();
|
||||
list.add(u);
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | txtParseList ==========未找到文件");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | txtParseList ==========解析失败!!");
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
d.close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* txt解析方法
|
||||
* @param url 文件路径
|
||||
* update 修改为不重复号码返回
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> txtParseListVyUrl(String url) throws IOException {
|
||||
List<String> list = new ArrayList<>();
|
||||
InputStream inputStream = new FileInputStream(url) ;
|
||||
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
|
||||
try {
|
||||
String count;
|
||||
while((count = d.readLine()) != null){
|
||||
String u = CharSequenceUtil.cleanBlank(count.toUpperCase());
|
||||
list.add(u);
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | txtParseList ==========未找到文件");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | txtParseList ==========解析失败!!");
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
d.close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* csv解析方法
|
||||
* @param inputStream 文件流
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> csvParseList(InputStream inputStream) throws IOException {
|
||||
List<String> list = new ArrayList<>();
|
||||
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try {
|
||||
String count;
|
||||
while((count = d.readLine()) != null){
|
||||
String u = count.toUpperCase();
|
||||
builder.append(u+",");
|
||||
}
|
||||
log.error("========== [builder.toString] =========="+builder.toString());
|
||||
if (builder!=null){
|
||||
String str= builder.toString();
|
||||
String[] split = str.split(",");
|
||||
for (String sp : split) {
|
||||
list.add(sp);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | csvParseList ==========未找到文件");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | csvParseList ==========解析失败!!");
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
d.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* csv解析方法
|
||||
* @param url 文件路径
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<String> csvParseListByUrl(String url) throws IOException {
|
||||
List<String> list = new ArrayList<>();
|
||||
InputStream inputStream = new FileInputStream(new File(url)) ;
|
||||
BufferedReader d = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try {
|
||||
String count;
|
||||
while((count = d.readLine()) != null){
|
||||
String u = count.toUpperCase();
|
||||
builder.append(u+",");
|
||||
}
|
||||
log.error("========== [builder.toString] =========="+builder.toString());
|
||||
if (builder!=null){
|
||||
String str= builder.toString();
|
||||
String[] split = str.split(",");
|
||||
for (String sp : split) {
|
||||
list.add(sp);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | csvParseList ==========未找到文件");
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.info("TxtUtils | csvParseList ==========解析失败!!");
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
d.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object[] 转 Java Bean
|
||||
* @param objectArray 原数组
|
||||
* @param clazz 目标 Bean
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> T objectArrayToBean(Object[] objectArray, Class<T> clazz) {
|
||||
if (objectArray == null || objectArray.length == 0){
|
||||
return null;
|
||||
}
|
||||
Class<?>[] tClass = null;
|
||||
Constructor<?>[] constructors = clazz.getConstructors();
|
||||
|
||||
for (int i = 0; i < constructors.length; i++){
|
||||
Constructor<?> constructor = constructors[i];
|
||||
Class<?>[] parameterTypes = constructor.getParameterTypes();
|
||||
if (parameterTypes.length == objectArray.length){
|
||||
tClass = parameterTypes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return clazz.getConstructor(tClass).newInstance(objectArray);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue