public abstract class IOUtil extends Object
| 构造器和说明 |
|---|
IOUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static long |
copyInToOut(InputStream from,
OutputStream to)
把InputStream复制到OutputStream
|
static void |
createFile(String fileName,
long fileSize)
创建指定大小的文件
|
static String |
doPostOrGet(String pathUrl,
String data,
String... heads)
以post或get方式调用对方接口方法, head头错误:tams:sqlIntercept:tenant_id
|
static InputStream |
fileToInputStream(String filePath,
Class classz)
通过class加载文件
|
static Properties |
fileToProperties(File filePath)
文件转为prop
|
static Properties |
fileToProperties(String filePath)
classpath的属性文件转为属性
|
static Properties |
fileToProperties(String filePath,
Class classz)
属性文件转为属性
|
static void |
findClassByFile(String packageName,
String packagePath,
boolean recursive,
Set<Class<?>> classes)
以文件的形式来获取包下的所有Class
|
static List<org.apache.commons.lang3.tuple.Pair<String,InputStream>>[] |
findFiles(String propFilePre,
URL root,
String rootDir,
String jarpre,
String suffix,
String... firstConfs)
得到指定根目录下的的文件(只要common-开头的jar文件)
|
static List<URL> |
findHasPackRootPath(String... packageNames) |
static List<org.apache.commons.lang3.tuple.Pair<String,InputStream>>[] |
findProps(String propFilePre,
URL root,
String rootDir,
String jarpre,
String... firstConfs) |
static Set<String> |
findSubClassByJars(String parentClassName,
int threadnum,
Set<String> jars,
javassist.ClassPool pool) |
static Set<Class<?>> |
getClasses(String pack,
boolean inSubPackage)
得到某个包下的所有class
|
static List<String> |
getClassNameFromDir(String classDir,
String packageName)
指定目录下的class文件
|
static List<String> |
getClassNameFromJar(String jarUrlStr,
String filtDirPath)
从jar文件里得到指定目录下的class名
|
static File |
getCurFolder(Class<?> classz) |
static File |
getCurFolder(Class<?> classz,
boolean isTarget)
得到当前目录 ,不打jar包: file:/D:/source/github/commons/target/classes/
打jar包:jar所在目录:E:\binlog
|
static String |
getDirForCommonUtilFilePath(String filePath)
得到此项目下的文件目录路径
|
static String |
getDirForFilePath(Class classStr,
String filePath)
得到指定Class下的文件的目录
|
static Map<String,InputStream> |
getFilesFromJar(String jarUrlStr,
String dirPath,
String... suffix)
查找jar中的某个目录下的所有文件,dirPath=“.”表示根目录下文件
\D:\greensoft\maven\repository\com\zhongan\plugins\za-maven-plugin\0.1\za
-maven-plugin-0.1.jar!
|
static List<org.apache.commons.lang3.tuple.Pair<String,InputStream>> |
getResources(String rootpackage,
String packageele,
String suffix)
找资源
|
static List<String> |
getSubType(String filepath,
String packageName,
String parentClassName,
javassist.ClassPool pool) |
static List<String> |
getSubTypeFromDir(String classDir,
String packageName,
String parentClassName,
javassist.ClassPool pool)
得到指定目录下的指定class的子class
|
static List<String> |
getSubTypeFromJar(String jarUrlStr,
String dirPath,
String parentClassName,
javassist.ClassPool pool)
得到jar里面指定class的子class
|
static boolean |
isBinFile(String filename) |
static boolean |
isSubClass(String subClass,
String parentClassName,
javassist.ClassPool pool) |
static JarFile |
jarRead(String jarUrlStr) |
static File[] |
listFile(String dirpath,
String pattern)
列出符合条件的文件
|
static String |
mergeFolderAndFilePath(String folderPath,
String... paths) |
static List<String> |
readFileReverse(String filename,
int maxNum) |
static List<String> |
readFileReverse(String filename,
int maxNum,
String charset,
boolean isKipnull) |
static void |
replaceDir(String oriPath,
String destPath,
String... replaceRule)
按规则替换整个目录下的文件
|
static void |
replaceFile(String oriPath,
String destPath,
Encoding oriEncoding,
Encoding destEncoding,
String... replaceRule)
把源模板文件替换为符合条件的目的文件
|
static void |
replaceFile(String oriPath,
String destPath,
String... replaceRule)
把源模板文件替换为符合条件的目的文件,用UTF-8编码
|
static void |
replaceFileByStr(String oriContext,
BasePath basePath,
String relaPath,
String... replaceRule)
代码文件内容并写文件,用UTF-8方法
|
static void |
replaceFileByStr(String oriContext,
String destPath,
Encoding oriEncoding,
Encoding destEncoding,
String... replaceRule)
代码文件内容并写文件
|
static void |
replaceFileByStr(String oriContext,
String destPath,
String... replaceRule)
代码文件内容并写文件,用UTF-8方法
|
static String |
replaceStr(String oriContext,
String... replaceRule)
替换相关内容
|
static void |
saveFile(String osPathTrue,
String context)
保存文件到指定地址
|
static void |
saveFilePathType(String pathTypeStr,
String context)
保存文件到指定地址
|
static String |
slurp(InputStream in) |
static String |
slurp(InputStream in,
Encoding oriEncoding)
转换输入流为字符串
|
static String |
slurp(String filePath) |
static byte[] |
slurpbyte(InputStream in)
把流转为byte[]
|
static String |
slurpPathTypePath(String pathTypePath)
通过pathType的路径得到字符器
|
static Properties |
StringToProperties(String propStr)
把字符串转为props,以"\n"区分换行
|
static void |
subClassFilter(List<String> allClassName,
String parentClassName,
javassist.ClassPool pool) |
public static boolean isBinFile(String filename)
public static String slurp(InputStream in, Encoding oriEncoding) throws IOException
in - 输入流oriEncoding - 源编码格式IOException - 转换出错public static String slurp(InputStream in) throws IOException
IOExceptionpublic static byte[] slurpbyte(InputStream in) throws IOException
in - IOExceptionpublic static Properties fileToProperties(String filePath, Class classz)
filePath - 文件路径classz - 要加载属性文件同jar包的类public static Properties StringToProperties(String propStr)
propStr - public static Properties fileToProperties(File filePath)
filePath - 属性文件public static InputStream fileToInputStream(String filePath, Class classz)
filePath - 文件所在路径classz - 文件所在jar包中的class名public static List<org.apache.commons.lang3.tuple.Pair<String,InputStream>>[] findProps(String propFilePre, URL root, String rootDir, String jarpre, String... firstConfs)
public static List<org.apache.commons.lang3.tuple.Pair<String,InputStream>>[] findFiles(String propFilePre, URL root, String rootDir, String jarpre, String suffix, String... firstConfs)
propFilePre - 属性文件的前缀root - 根目录rootDir - 相对目录jarpre - 是过滤的jar包前缀suffix - 要得到的文件后缀firstConfs - 需要首先加载的文件名public static Properties fileToProperties(String filePath)
filePath - 文件路径public static String mergeFolderAndFilePath(String folderPath, String... paths)
public static String getDirForFilePath(Class classStr, String filePath)
classStr - 指定的classfilePath - 文件的相对路径public static String getDirForCommonUtilFilePath(String filePath)
filePath - 文件路径public static long copyInToOut(InputStream from, OutputStream to) throws IOException
from - 输入流to - 输出流IOException - 操作异常public static void replaceFile(String oriPath, String destPath, Encoding oriEncoding, Encoding destEncoding, String... replaceRule) throws IOException
oriPath - 源文件路径destPath - 目标文件路径oriEncoding - 源文件编码destEncoding - 目标文件编码replaceRule - 替换规则IOException - IO异常public static void replaceFileByStr(String oriContext, String destPath, Encoding oriEncoding, Encoding destEncoding, String... replaceRule) throws IOException
oriContext - 要处理的文件内容destPath - 目标文件路径oriEncoding - 源文件编码destEncoding - 目标文件编码replaceRule - 替换规则IOException - IO异常public static String replaceStr(String oriContext, String... replaceRule)
oriContext - replaceRule - public static void replaceFileByStr(String oriContext, String destPath, String... replaceRule) throws IOException
oriContext - 要处理的文件内容destPath - 目标文件路径replaceRule - 替换规则IOException - IO异常public static void replaceFileByStr(String oriContext, BasePath basePath, String relaPath, String... replaceRule) throws IOException
oriContext - 要处理的文件内容basePath - 基础路径relaPath - 相对路径replaceRule - 替换规则IOException - IO异常public static void replaceFile(String oriPath, String destPath, String... replaceRule) throws IOException
oriPath - 源文件路径destPath - 目标文件路径replaceRule - 替换规则IOException - IO异常public static void replaceDir(String oriPath, String destPath, String... replaceRule) throws IOException
oriPath - 源路径destPath - 目的路径replaceRule - 替换规则IOException - IO异常public static Map<String,InputStream> getFilesFromJar(String jarUrlStr, String dirPath, String... suffix) throws Exception
jarUrlStr - jar文件路径dirPath - jar里的目录路径suffix - 要过滤的前缀Exception - 读文件异常public static JarFile jarRead(String jarUrlStr) throws MalformedURLException, IOException
public static List<String> getClassNameFromJar(String jarUrlStr, String filtDirPath) throws Exception
jarUrlStr - jar文件路径filtDirPath - jar里的目录路径Exception - 读文件异常public static List<String> getClassNameFromDir(String classDir, String packageName)
classDir - class的目录路径packageName - 指定的的包目录public static List<String> getSubTypeFromJar(String jarUrlStr, String dirPath, String parentClassName, javassist.ClassPool pool) throws Exception
jarUrlStr - jar文件路径dirPath - jar里的目录路径parentClassName - 父类的类名pool - 类池Exception - 读文件异常public static List<String> getSubTypeFromDir(String classDir, String packageName, String parentClassName, javassist.ClassPool pool) throws Exception
classDir - 类目录packageName - 类目录下的包名parentClassName - 指定父类pool - 类池Exception - 读文件异常public static List<String> getSubType(String filepath, String packageName, String parentClassName, javassist.ClassPool pool) throws Exception
Exceptionpublic static void subClassFilter(List<String> allClassName, String parentClassName, javassist.ClassPool pool) throws javassist.NotFoundException
javassist.NotFoundExceptionpublic static boolean isSubClass(String subClass, String parentClassName, javassist.ClassPool pool) throws javassist.NotFoundException
javassist.NotFoundExceptionpublic static Set<String> findSubClassByJars(String parentClassName, int threadnum, Set<String> jars, javassist.ClassPool pool) throws Exception
Exceptionpublic static File getCurFolder(Class<?> classz, boolean isTarget)
classz - 项目包括的ClassisTarget - 是否到根目录,true:去掉classes false:不去掉classespublic static List<String> readFileReverse(String filename, int maxNum, String charset, boolean isKipnull)
public static void createFile(String fileName, long fileSize) throws IOException
fileName - 文件名fileSize - 文件大小IOException - 创建文件异常public static Set<Class<?>> getClasses(String pack, boolean inSubPackage)
pack - 包名inSubPackage - 是否包括子包public static void saveFile(String osPathTrue, String context)
osPathTrue - context - public static void saveFilePathType(String pathTypeStr, String context)
pathTypeStr - PathType类型的路径context - 要保存的文件 内容public static void findClassByFile(String packageName, String packagePath, boolean recursive, Set<Class<?>> classes)
packageName - 包名packagePath - 包路径recursive - 是否穷取子孙目录classes - 查到的结果public static List<org.apache.commons.lang3.tuple.Pair<String,InputStream>> getResources(String rootpackage, String packageele, String suffix)
rootpackage - 存在指定java包的jar包,用于过滤jar包,如:net.wicp.tams.caspackageele - packageele 存放xml文件的相对路径,如:mybatis/cas/sqlmapsuffix - 文件后缀,如:xmlpublic static File[] listFile(String dirpath, String pattern)
dirpath - 父目录pattern - 模式Copyright © 2023. All rights reserved.