org.test4j.tools.commons
类 ResourceHelper

java.lang.Object
  继承者 org.test4j.tools.commons.ResourceHelper

public class ResourceHelper
extends Object


构造方法摘要
ResourceHelper()
           
 
方法摘要
static String convertStreamToSQL(InputStream is)
          过滤file文件中的注释代码
static void copyClassPathResource(String classPathResourceName, File fileSystemResourceFile)
          把classpath中的文件内容复制到指定的外部文件中
static void copyClassPathResource(String classPathResourceName, String fileSystemResourceName)
          把classpath中的文件内容复制到指定的外部文件中
static void copyClassPathResourceToDir(String classPathResourceName, String fileSystemDirectoryName)
          将classpath下的文件拷贝到fileSystemDirectoryName目录下
static String defaultFileEncoding()
          文件缺省的编码格式
static boolean deleteFileOrDir(File path)
          删除文件或目录
static boolean deleteFileOrDir(String path)
          删除文件或目录
static File findWikiFile(Class claz, String url)
          查找文件
static String getFileEncodingCharset(File file)
          获得的文件的编码格式
static String getFileEncodingCharset(InputStream is)
          获得的文件流的编码格式
static InputStream getResourceAsStream(Class clazz, String fileName)
          先读取claz所在package下的url资源
如果没有找到,在读取跟classpath下的url资源
static InputStream getResourceAsStream(String file)
          根据文件名称返回文件输入流

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取 classpath下文件
static URL getResourceUrl(String filename)
          返回文件的URL

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取 classpath下文件
static String getSuffixPath(File basePath, String filePath)
          获得javaFile相对于basePath的子路径
例如
filePath = src/java/org/test4j/reflector/helper/ClazzHelper.java
basepath = src/java/org/test4j
那么返回值就为 reflector/helper/ClazzHelper.java
static URL getUrl(File file)
          Creates an URL that points to the given file.
static boolean isJarFile(File classRoot)
          是否是jar文件
static boolean isResourceExists(Class claz, String file)
          判断在claz对应的package下面是否存在名称为file的文件
static Properties loadPropertiesFrom(String file)
          从文件中价值配置项

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取 classpath下文件
static void mkFileParentDir(File file)
          创建文件file所在的父目录
static void mkFileParentDir(String file)
          创建文件file所在的父目录
static String readFromFile(Class clazz, String fileName)
          读取文件内容
*
o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则, 先读取clazz path下的fileName文件,再读取跟路径下的fileName文件
static String readFromFile(File file)
          从文本文件中读取内容
static String readFromFile(String file)
          从文本文件中读取内容

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取跟 classpath下filePath文件
static String readFromStream(InputStream is)
          To convert the InputStream to String we use the BufferedReader.readLine() method.
static String readFromStream(InputStream is, String encoding)
          To convert the InputStream to String we use the BufferedReader.readLine() method.
static String[] readLinesFromFile(String filePath)
          按行读取文件
static String[] readLinesFromFile(String filePath, String encoding)
           
static String[] readLinesFromStream(InputStream is)
          从文件流中读取文本行
static String[] readLinesFromStream(InputStream is, String encoding)
          从文件流中读取文本行
static void writeStringToFile(File file, String content)
          写字符串到文件中
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

ResourceHelper

public ResourceHelper()
方法详细信息

readFromStream

public static String readFromStream(InputStream is,
                                    String encoding)
To convert the InputStream to String we use the BufferedReader.readLine() method. We iterate until the BufferedReader return null which means there's no more data to read. Each line will appended to a StringBuilder and returned as String.

参数:
is -
encoding - 编码格式
返回:

readFromStream

public static String readFromStream(InputStream is)
To convert the InputStream to String we use the BufferedReader.readLine() method. We iterate until the BufferedReader return null which means there's no more data to read. Each line will appended to a StringBuilder and returned as String.

参数:
is -
返回:

readLinesFromStream

public static String[] readLinesFromStream(InputStream is,
                                           String encoding)
从文件流中读取文本行

参数:
is -
encoding - 编码格式
返回:
返回文本行列表

readLinesFromStream

public static String[] readLinesFromStream(InputStream is)
从文件流中读取文本行

参数:
is -
返回:
返回文本行列表

writeStringToFile

public static void writeStringToFile(File file,
                                     String content)
写字符串到文件中

参数:
file -
content -

copyClassPathResource

public static void copyClassPathResource(String classPathResourceName,
                                         String fileSystemResourceName)
把classpath中的文件内容复制到指定的外部文件中

参数:
classPathFile - classpath下资源文件
outputFile - 拷贝目标的系统文件名称

copyClassPathResource

public static void copyClassPathResource(String classPathResourceName,
                                         File fileSystemResourceFile)
把classpath中的文件内容复制到指定的外部文件中

参数:
classPathResourceName - classpath下资源文件
fileSystemResourceFile - 拷贝目标的系统文件

copyClassPathResourceToDir

public static void copyClassPathResourceToDir(String classPathResourceName,
                                              String fileSystemDirectoryName)
将classpath下的文件拷贝到fileSystemDirectoryName目录下

参数:
classPathResourceName - classpath下的资源文件
fileSystemDirectoryName - 拷贝目标的系统文件目录名

getUrl

public static URL getUrl(File file)
Creates an URL that points to the given file.

参数:
file - The file, not null
返回:
The URL to the file, not null

findWikiFile

public static File findWikiFile(Class claz,
                                String url)
                         throws Exception
查找文件

参数:
claz -
url -
返回:
抛出:
Exception

defaultFileEncoding

public static String defaultFileEncoding()
文件缺省的编码格式

返回:

getFileEncodingCharset

public static String getFileEncodingCharset(File file)
获得的文件的编码格式

参数:
file -
返回:

getFileEncodingCharset

public static String getFileEncodingCharset(InputStream is)
获得的文件流的编码格式

参数:
file -
返回:

getResourceAsStream

public static InputStream getResourceAsStream(String file)
                                       throws FileNotFoundException
根据文件名称返回文件输入流

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取 classpath下文件

参数:
file -
返回:
抛出:
FileNotFoundException

getResourceUrl

public static URL getResourceUrl(String filename)
返回文件的URL

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取 classpath下文件

参数:
filename -
返回:

getResourceAsStream

public static InputStream getResourceAsStream(Class clazz,
                                              String fileName)
                                       throws FileNotFoundException
先读取claz所在package下的url资源
如果没有找到,在读取跟classpath下的url资源

参数:
claz -
fileName -
返回:
抛出:
FileNotFoundException

readFromFile

public static String readFromFile(String file)
                           throws FileNotFoundException
从文本文件中读取内容

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取跟 classpath下filePath文件

参数:
filePath -
encoding - 文件编码
返回:
抛出:
FileNotFoundException

readFromFile

public static String readFromFile(File file)
                           throws FileNotFoundException
从文本文件中读取内容

参数:
file -
返回:
抛出:
FileNotFoundException

readFromFile

public static String readFromFile(Class clazz,
                                  String fileName)
                           throws FileNotFoundException
读取文件内容
*
o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则, 先读取clazz path下的fileName文件,再读取跟路径下的fileName文件

参数:
clazz - 文件所在的class package
filePath -
返回:
抛出:
FileNotFoundException

readLinesFromFile

public static String[] readLinesFromFile(String filePath)
                                  throws FileNotFoundException
按行读取文件

参数:
filePath -
返回:
抛出:
FileNotFoundException

readLinesFromFile

public static String[] readLinesFromFile(String filePath,
                                         String encoding)
                                  throws FileNotFoundException
抛出:
FileNotFoundException

loadPropertiesFrom

public static Properties loadPropertiesFrom(String file)
从文件中价值配置项

o file:开头读取文件系统
o classpath:开头读取classpath下的文件
o 否则读取 classpath下文件

参数:
file -
返回:
抛出:
FileNotFoundException

isResourceExists

public static boolean isResourceExists(Class claz,
                                       String file)
判断在claz对应的package下面是否存在名称为file的文件

参数:
claz -
file -
返回:

convertStreamToSQL

public static String convertStreamToSQL(InputStream is)
过滤file文件中的注释代码

参数:
is -
返回:

getSuffixPath

public static String getSuffixPath(File basePath,
                                   String filePath)
获得javaFile相对于basePath的子路径
例如
filePath = src/java/org/test4j/reflector/helper/ClazzHelper.java
basepath = src/java/org/test4j
那么返回值就为 reflector/helper/ClazzHelper.java

参数:
basePath - 跟路径
filePath - 文件绝对路径名称
返回:

deleteFileOrDir

public static boolean deleteFileOrDir(String path)
删除文件或目录

参数:
path -
返回:

deleteFileOrDir

public static boolean deleteFileOrDir(File path)
删除文件或目录

参数:
path -
返回:

mkFileParentDir

public static void mkFileParentDir(String file)
创建文件file所在的父目录

参数:
file -

mkFileParentDir

public static void mkFileParentDir(File file)
创建文件file所在的父目录

参数:
file -

isJarFile

public static boolean isJarFile(File classRoot)
是否是jar文件

参数:
classRoot -
返回:


Copyright © 2013. All rights reserved.