public class Utils extends Object
| Modifier and Type | Field and Description |
|---|---|
static char[] |
CS |
protected static org.slf4j.Logger |
log |
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static File |
baseDir(String child)
项目根目录下边找目录或文件
|
static String |
buildUrl(String urlStr,
Map<String,Object> params)
把查询参数添加到 url 后边
|
static <S,T> Copier<S,T> |
copier(S src,
T target)
对象 复制器
|
static Httper |
http()
构建一个 http 请求, 支持 get, post.
|
static long |
ioCopy(InputStream is,
OutputStream os)
io 流 copy
|
static long |
ioCopy(InputStream is,
OutputStream os,
Integer bufSize)
io 流 copy
try (InputStream is = new FileInputStream("d:/tmp/1.txt"); OutputStream os = new FileOutputStream("d:/tmp/2.txt")) {
Utils.ioCopy(is, os);
}
|
static String |
ipv4()
本机ipv4地址
|
static boolean |
isLinux()
判断系统是否为 linux 系统
判断方法来源 io.netty.channel.epoll.Native#loadNativeLibrary()
|
static void |
iterateField(Class clz,
Consumer<Field> fn)
查找字段
|
static void |
iterateMethod(Class clz,
Consumer<Method> fn)
遍历所有方法并处理
|
static String |
md5Hex(byte[] bs)
md5 hex
|
static String |
pid()
得到jvm进程号
|
static String |
random(int length)
随机字符串(区分大小写)
|
static String |
random(int length,
String prefix,
String suffix)
随机字符串(区分大小写)
|
static byte[] |
sha1(byte[] bs)
sha1 加密
|
static Tailer |
tailer()
文件内容监控器(类linux tail)
|
static <T> T |
to(Object v,
Class<T> type)
类型转换
|
public static String pid()
public static boolean isLinux()
public static String ipv4()
public static byte[] sha1(byte[] bs)
bs - 被加密码byte[]public static String md5Hex(byte[] bs)
bs - 被加密的byte[]public static String random(int length, String prefix, String suffix)
length - 长度prefix - 前缀suffix - 后缀public static String random(int length)
length - 长度public static <T> T to(Object v, Class<T> type)
v - 值type - 转换的类型public static void iterateMethod(Class clz, Consumer<Method> fn)
clz - Classfn - 函数public static void iterateField(Class clz, Consumer<Field> fn)
clz - Classfn - 函数public static String buildUrl(String urlStr, Map<String,Object> params)
urlStr - urlparams - 参数public static <S,T> Copier<S,T> copier(S src, T target)
S - 源对象类型T - 目标对象类型src - 源对象target - 目标对象Copierpublic static long ioCopy(InputStream is, OutputStream os, Integer bufSize) throws IOException
try (InputStream is = new FileInputStream("d:/tmp/1.txt"); OutputStream os = new FileOutputStream("d:/tmp/2.txt")) {
Utils.ioCopy(is, os);
}
is - 输入流os - 输出流bufSize - 每次读取字节大小IOException - OutputStream.write(byte[], int, int)public static long ioCopy(InputStream is, OutputStream os) throws IOException
is - 输入流os - 输出流IOException - OutputStream.write(byte[], int, int)Copyright © 2022. All rights reserved.