Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
94fe6911
A
AndroidUtilCode
项目概览
mmm-rain
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
94fe6911
编写于
8月 21, 2016
作者:
B
blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 08/21 log
上级
954b97fc
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
304 addition
and
118 deletion
+304
-118
README.md
README.md
+2
-1
update_log.md
update_log.md
+21
-20
utilcode/build.gradle
utilcode/build.gradle
+2
-2
utilcode/proguard-rules.pro
utilcode/proguard-rules.pro
+4
-0
utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java
...de/src/main/java/com/blankj/utilcode/utils/FileUtils.java
+46
-23
utilcode/src/test/java/com/blankj/utilcode/utils/EncryptUtilsTest.java
...test/java/com/blankj/utilcode/utils/EncryptUtilsTest.java
+18
-10
utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest.java
...rc/test/java/com/blankj/utilcode/utils/FileUtilsTest.java
+180
-54
utilcode/src/test/java/com/blankj/utilcode/utils/TestUtils.java
...de/src/test/java/com/blankj/utilcode/utils/TestUtils.java
+23
-0
utilcode/src/test/res/encrypt/MD5.txt
utilcode/src/test/res/encrypt/MD5.txt
+0
-0
utilcode/src/test/res/file/GBK.txt
utilcode/src/test/res/file/GBK.txt
+0
-0
utilcode/src/test/res/file/UTF16BE.txt
utilcode/src/test/res/file/UTF16BE.txt
+0
-0
utilcode/src/test/res/file/UTF8.txt
utilcode/src/test/res/file/UTF8.txt
+0
-0
utilcode/src/test/res/file/Unicode.txt
utilcode/src/test/res/file/Unicode.txt
+0
-0
utilcode/src/test/res/new Dir
utilcode/src/test/res/new Dir
+0
-0
utilcode/utilcode.iml
utilcode/utilcode.iml
+8
-8
未找到文件。
README.md
浏览文件 @
94fe6911
...
...
@@ -66,6 +66,7 @@
> - AES解密 *decryptAES*
> - **文件相关→[FileUtils.java][file.java]→[Test][file.test]**
> - 关闭IO *closeIO*
> - 根据文件路径获取文件 *getFileByPath*
> - 判断文件是否存在 *isFileExists*
> - 判断是否是目录 *isDir*
...
...
@@ -214,7 +215,7 @@
***
Gradle:
```
groovy
compile
'com.blankj:utilcode:1.1.
1
'
compile
'com.blankj:utilcode:1.1.
2
'
```
### Proguard
...
...
update_log.md
浏览文件 @
94fe6911
### 更新Log
#### 16/08/19 更新目录,继续完善FileUtils
#### 16/08/19 继续完善FileUtils及单元测试
#### 16/08/21 FileUtils单元测试完毕,修复FileUtils的bug,发布版本1.1.2
#### 16/08/20 更新目录,继续完善FileUtils单元测试,发布版本1.1.1
#### 16/08/19 继续完善FileUtils及单元测试,及其他小修小补(在此感谢vpop的三次Pr)
#### 16/08/18 完善FileUtils及单元测试,完善ImageUtils
#### 16/08/17 完善FileUtils
#### 16/08/16 新增StringUtils及单元测试,完善正则工具类,版本更新1.1.0
...
...
utilcode/build.gradle
浏览文件 @
94fe6911
...
...
@@ -7,8 +7,8 @@ android {
defaultConfig
{
minSdkVersion
11
targetSdkVersion
23
versionCode
3
versionName
"1.1.
1
"
versionCode
4
versionName
"1.1.
2
"
}
buildTypes
{
release
{
...
...
utilcode/proguard-rules.pro
浏览文件 @
94fe6911
...
...
@@ -15,3 +15,7 @@
#-
keepclassmembers
class
fqcn
.
of
.
javascript
.
interface
.
for
.
webview
{
#
public
*
;
#
}
#-
keep
class
com
.
blankj
.
utilcode
.
**
{
*
;
}
#-
keepclassmembers
class
com
.
blankj
.
utilcode
.
**
{
*
;
}
#-
dontwarn
com
.
blankj
.
utilcode
.
**
\ No newline at end of file
utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java
浏览文件 @
94fe6911
...
...
@@ -34,9 +34,11 @@ public class FileUtils {
}
/**
* 关闭IO
*
* @param closeable closeable
*/
p
rivate
static
void
closeIO
(
Closeable
closeable
)
{
p
ublic
static
void
closeIO
(
Closeable
closeable
)
{
if
(
closeable
==
null
)
return
;
try
{
closeable
.
close
();
...
...
@@ -132,7 +134,8 @@ public class FileUtils {
* @return {@code true}: 存在或创建成功<br>{@code false}: 不存在或创建失败
*/
public
static
boolean
createOrExistsDir
(
File
file
)
{
return
file
!=
null
&&
(
file
.
exists
()
&&
file
.
isDirectory
()
||
file
.
mkdirs
());
// 如果存在,是目录则返回true,是文件则返回false,不存在则返回是否创建成功
return
file
!=
null
&&
(
file
.
exists
()
?
file
.
isDirectory
()
:
file
.
mkdirs
());
}
/**
...
...
@@ -153,7 +156,8 @@ public class FileUtils {
*/
public
static
boolean
createOrExistsFile
(
File
file
)
{
if
(
file
==
null
)
return
false
;
if
(
file
.
exists
()
&&
file
.
isFile
())
return
true
;
// 如果存在,是文件则返回true,是目录则返回false
if
(
file
.
exists
())
return
file
.
isFile
();
if
(!
createOrExistsDir
(
file
.
getParentFile
()))
return
false
;
try
{
return
file
.
createNewFile
();
...
...
@@ -215,22 +219,29 @@ public class FileUtils {
*/
private
static
boolean
copyOrMoveDir
(
File
srcDir
,
File
destDir
,
boolean
isMove
)
{
if
(
srcDir
==
null
||
destDir
==
null
)
return
false
;
// 如果目标目录在源目录中则返回false,看不懂的话好好想想递归怎么结束
// srcPath : F:\\MyGithub\\AndroidUtilCode\\utilcode\\src\\test\\res
// destPath: F:\\MyGithub\\AndroidUtilCode\\utilcode\\src\\test\\res1
// 为防止以上这种情况出现出现误判,须分别在后面加个路径分隔符
String
srcPath
=
srcDir
.
getPath
()
+
File
.
separator
;
String
destPath
=
destDir
.
getPath
()
+
File
.
separator
;
if
(
destPath
.
contains
(
srcPath
))
return
false
;
// 源文件不存在或者不是目录则返回false
if
(!
srcDir
.
exists
()
||
!
srcDir
.
isDirectory
())
return
false
;
// 目标目录不存在返回false
if
(!
createOrExistsDir
(
destDir
))
return
false
;
File
[]
srcDirFiles
=
srcDir
.
listFiles
();
for
(
File
srcDirFile
:
srcDirFiles
)
{
File
oneDestFile
=
new
File
(
destDir
.
getPath
()
+
File
.
separator
+
srcDirFile
.
getName
());
if
(
srcDirFile
.
isFile
())
{
copyOrMoveFile
(
srcDirFile
,
oneDestFile
,
isMove
);
}
else
if
(
srcDirFile
.
isDirectory
())
{
copyOrMoveDir
(
srcDirFile
,
oneDestFile
,
isMove
);
File
[]
files
=
srcDir
.
listFiles
();
for
(
File
file
:
files
)
{
File
oneDestFile
=
new
File
(
destPath
+
file
.
getName
());
if
(
file
.
isFile
())
{
// 如果操作失败返回false
if
(!
copyOrMoveFile
(
file
,
oneDestFile
,
isMove
))
return
false
;
}
else
if
(
file
.
isDirectory
())
{
// 如果操作失败返回false
if
(!
copyOrMoveDir
(
file
,
oneDestFile
,
isMove
))
return
false
;
}
if
(
isMove
&&
!
deleteFile
(
srcDirFile
))
return
false
;
}
return
true
;
return
!
isMove
||
deleteDir
(
srcDir
)
;
}
/**
...
...
@@ -262,7 +273,8 @@ public class FileUtils {
// 目标目录不存在返回false
if
(!
createOrExistsDir
(
destFile
.
getParentFile
()))
return
false
;
try
{
return
writeFileFromIS
(
destFile
,
new
FileInputStream
(
srcFile
),
false
)
&&
!(
isMove
&&
!
deleteFile
(
srcFile
));
return
writeFileFromIS
(
destFile
,
new
FileInputStream
(
srcFile
),
false
)
&&
!(
isMove
&&
!
deleteFile
(
srcFile
));
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
return
false
;
...
...
@@ -276,8 +288,8 @@ public class FileUtils {
* @param destDirPath 目标目录路径
* @return {@code true}: 复制成功<br>{@code false}: 复制失败
*/
public
boolean
copyDir
(
String
srcDirPath
,
String
destDirPath
)
{
return
move
Dir
(
getFileByPath
(
srcDirPath
),
getFileByPath
(
destDirPath
));
public
static
boolean
copyDir
(
String
srcDirPath
,
String
destDirPath
)
{
return
copy
Dir
(
getFileByPath
(
srcDirPath
),
getFileByPath
(
destDirPath
));
}
/**
...
...
@@ -296,7 +308,7 @@ public class FileUtils {
*
* @param srcFilePath 源文件路径
* @param destFilePath 目标文件路径
* @return {@code true}: 复制
拷贝
成功<br>{@code false}: 复制失败
* @return {@code true}: 复制成功<br>{@code false}: 复制失败
*/
public
static
boolean
copyFile
(
String
srcFilePath
,
String
destFilePath
)
{
return
copyFile
(
getFileByPath
(
srcFilePath
),
getFileByPath
(
destFilePath
));
...
...
@@ -320,7 +332,7 @@ public class FileUtils {
* @param destDirPath 目标目录路径
* @return {@code true}: 移动成功<br>{@code false}: 移动失败
*/
public
boolean
moveDir
(
String
srcDirPath
,
String
destDirPath
)
{
public
static
boolean
moveDir
(
String
srcDirPath
,
String
destDirPath
)
{
return
moveDir
(
getFileByPath
(
srcDirPath
),
getFileByPath
(
destDirPath
));
}
...
...
@@ -363,7 +375,7 @@ public class FileUtils {
* @param dirPath 目录路径
* @return {@code true}: 删除成功<br>{@code false}: 删除失败
*/
public
boolean
deleteDir
(
String
dirPath
)
{
public
static
boolean
deleteDir
(
String
dirPath
)
{
return
deleteDir
(
getFileByPath
(
dirPath
));
}
...
...
@@ -373,9 +385,11 @@ public class FileUtils {
* @param dir 目录
* @return {@code true}: 删除成功<br>{@code false}: 删除失败
*/
public
boolean
deleteDir
(
File
dir
)
{
public
static
boolean
deleteDir
(
File
dir
)
{
if
(
dir
==
null
)
return
false
;
// 目录不存在返回true
if
(!
dir
.
exists
())
return
true
;
// 不是目录返回false
if
(!
dir
.
isDirectory
())
return
false
;
// 现在文件存在且是文件夹
File
[]
files
=
dir
.
listFiles
();
...
...
@@ -436,7 +450,10 @@ public class FileUtils {
try
{
os
=
new
BufferedOutputStream
(
new
FileOutputStream
(
file
,
append
));
byte
data
[]
=
new
byte
[
KB
];
while
(
is
.
read
(
data
)
!=
-
1
)
os
.
write
(
data
);
int
len
;
while
((
len
=
is
.
read
(
data
))
!=
-
1
)
{
os
.
write
(
data
,
0
,
len
);
}
return
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
@@ -589,7 +606,8 @@ public class FileUtils {
* @param charsetName 编码格式
* @return 包含制定行的list
*/
public
static
List
<
String
>
readFile2List
(
String
filePath
,
int
start
,
int
end
,
String
charsetName
)
{
public
static
List
<
String
>
readFile2List
(
String
filePath
,
int
start
,
int
end
,
String
charsetName
)
{
return
readFile2List
(
getFileByPath
(
filePath
),
start
,
end
,
charsetName
);
}
...
...
@@ -653,7 +671,12 @@ public class FileUtils {
BufferedReader
reader
=
null
;
try
{
sb
=
new
StringBuilder
();
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
file
),
charsetName
));
if
(
StringUtils
.
isSpace
(
charsetName
))
{
reader
=
new
BufferedReader
(
new
FileReader
(
file
));
}
else
{
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
file
),
charsetName
));
}
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
line
);
...
...
utilcode/src/test/java/com/blankj/utilcode/utils/EncryptUtilsTest.java
浏览文件 @
94fe6911
...
...
@@ -29,8 +29,10 @@ public class EncryptUtilsTest {
String
blankjSHA1
=
"C606ACCB1FEB669E19D080ADDDDBB8E6CDA5F43C"
;
String
blankjSHA224
=
"F4C5C0E8CF56CAC4D06DB6B523F67621859A9D79BDA4B2AC03097D5F"
;
String
blankjSHA256
=
"8BD80AE90DFBA112786367BEBDDEE60A638EF5B82682EDF8F3D3CA8E6BFEF648"
;
String
blankjSHA384
=
"BF831E5221FC108D6A72ACB888BA3EB0C030A5F01BA2F739856BE70681D86F992B85E0D461101C74BAEDA895BD422557"
;
String
blankjSHA512
=
"D59D31067F614ED3586F85A31FEFDB7F33096316DA26EBE0FF440B241C8560D96650F100D78C512560C976949EFA89CB5D5589DCF68C7FAADE98F03BCFEC2B45"
;
String
blankjSHA384
=
"BF831E5221FC108D6A72ACB888BA3EB0C030A5F01BA2F739856BE70681D86F992B85E0D461101C74BAEDA895BD422557"
;
String
blankjSHA512
=
"D59D31067F614ED3586F85A31FEFDB7F33096316DA26EBE0FF440B241C8560D96650F100D78C512560C976949EFA89CB5D5589DCF68C7FAADE98F03BCFEC2B45"
;
@Test
public
void
testEncryptMD2
()
throws
Exception
{
...
...
@@ -92,14 +94,16 @@ public class EncryptUtilsTest {
public
void
testEncryptDES
()
throws
Exception
{
assertThat
(
encryptDES
(
bytesDataDES
,
bytesKeyDES
)).
isEqualTo
(
bytesResDES
);
assertThat
(
encryptDES2HexString
(
bytesDataDES
,
bytesKeyDES
)).
isEqualTo
(
resDES
);
assertThat
(
encryptDES2Base64
(
bytesDataDES
,
bytesKeyDES
)).
isEqualTo
(
base64Encode
(
bytesResDES
));
assertThat
(
encryptDES2Base64
(
bytesDataDES
,
bytesKeyDES
)).
isEqualTo
(
base64Encode
(
bytesResDES
));
}
@Test
public
void
testDecryptDES
()
throws
Exception
{
assertThat
(
decryptDES
(
bytesResDES
,
bytesKeyDES
)).
isEqualTo
(
bytesDataDES
);
assertThat
(
decryptHexStringDES
(
resDES
,
bytesKeyDES
)).
isEqualTo
(
bytesDataDES
);
assertThat
(
decryptBase64DES
(
base64Encode
(
bytesResDES
),
bytesKeyDES
)).
isEqualTo
(
bytesDataDES
);
assertThat
(
decryptBase64DES
(
base64Encode
(
bytesResDES
),
bytesKeyDES
)).
isEqualTo
(
bytesDataDES
);
}
String
data3DES
=
"1111111111111111"
;
...
...
@@ -113,14 +117,16 @@ public class EncryptUtilsTest {
public
void
testEncrypt3DES
()
throws
Exception
{
assertThat
(
encrypt3DES
(
bytesDataDES3
,
bytesKeyDES3
)).
isEqualTo
(
bytesResDES3
);
assertThat
(
encrypt3DES2HexString
(
bytesDataDES3
,
bytesKeyDES3
)).
isEqualTo
(
res3DES
);
assertThat
(
encrypt3DES2Base64
(
bytesDataDES3
,
bytesKeyDES3
)).
isEqualTo
(
base64Encode
(
bytesResDES3
));
assertThat
(
encrypt3DES2Base64
(
bytesDataDES3
,
bytesKeyDES3
)).
isEqualTo
(
base64Encode
(
bytesResDES3
));
}
@Test
public
void
testDecrypt3DES
()
throws
Exception
{
assertThat
(
decrypt3DES
(
bytesResDES3
,
bytesKeyDES3
)).
isEqualTo
(
bytesDataDES3
);
assertThat
(
decryptHexString3DES
(
res3DES
,
bytesKeyDES3
)).
isEqualTo
(
bytesDataDES3
);
assertThat
(
decryptBase64_3DES
(
base64Encode
(
bytesResDES3
),
bytesKeyDES3
)).
isEqualTo
(
bytesDataDES3
);
assertThat
(
decryptBase64_3DES
(
base64Encode
(
bytesResDES3
),
bytesKeyDES3
)).
isEqualTo
(
bytesDataDES3
);
}
String
dataAES
=
"11111111111111111111111111111111"
;
...
...
@@ -134,21 +140,23 @@ public class EncryptUtilsTest {
public
void
testEncryptAES
()
throws
Exception
{
assertThat
(
encryptAES
(
bytesDataAES
,
bytesKeyAES
)).
isEqualTo
(
bytesResAES
);
assertThat
(
encryptAES2HexString
(
bytesDataAES
,
bytesKeyAES
)).
isEqualTo
(
resAES
);
assertThat
(
encryptAES2Base64
(
bytesDataAES
,
bytesKeyAES
)).
isEqualTo
(
base64Encode
(
bytesResAES
));
assertThat
(
encryptAES2Base64
(
bytesDataAES
,
bytesKeyAES
)).
isEqualTo
(
base64Encode
(
bytesResAES
));
}
@Test
public
void
testDecryptAES
()
throws
Exception
{
assertThat
(
decryptAES
(
bytesResAES
,
bytesKeyAES
)).
isEqualTo
(
bytesDataAES
);
assertThat
(
decryptHexStringAES
(
resAES
,
bytesKeyAES
)).
isEqualTo
(
bytesDataAES
);
assertThat
(
decryptBase64AES
(
base64Encode
(
bytesResAES
),
bytesKeyAES
)).
isEqualTo
(
bytesDataAES
);
assertThat
(
decryptBase64AES
(
base64Encode
(
bytesResAES
),
bytesKeyAES
)).
isEqualTo
(
bytesDataAES
);
}
String
path
=
System
.
getProperty
(
"user.dir"
)
+
"\\src\\test\\res\\"
;
String
path
=
TestUtils
.
BASEPATH
+
"encrypt"
+
TestUtils
.
SEP
;
String
md5
=
"7F138A09169B250E9DCB378140907378"
;
@Test
public
void
testEncryptMD5File
()
throws
Exception
{
assertThat
(
encryptMD5File2String
(
new
File
(
path
+
File
.
separator
+
"MD5.txt"
))).
isEqualTo
(
md5
);
assertThat
(
encryptMD5File2String
(
new
File
(
path
+
"MD5.txt"
))).
isEqualTo
(
md5
);
}
}
\ No newline at end of file
utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest.java
浏览文件 @
94fe6911
...
...
@@ -2,7 +2,11 @@ package com.blankj.utilcode.utils;
import
org.junit.Test
;
import
java.io.FileInputStream
;
import
static
com
.
blankj
.
utilcode
.
utils
.
FileUtils
.*;
import
static
com
.
blankj
.
utilcode
.
utils
.
TestUtils
.
BASEPATH
;
import
static
com
.
blankj
.
utilcode
.
utils
.
TestUtils
.
SEP
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
/**
...
...
@@ -15,7 +19,14 @@ import static com.google.common.truth.Truth.assertThat;
*/
public
class
FileUtilsTest
{
String
path
=
System
.
getProperty
(
"user.dir"
)
+
"\\src\\test\\res\\"
;
String
path
=
BASEPATH
+
"file"
+
SEP
;
@Test
public
void
testGetFileByPath
()
throws
Exception
{
assertThat
(
getFileByPath
(
" "
)).
isNull
();
assertThat
(
getFileByPath
(
"c:"
)).
isNotNull
();
}
@Test
public
void
testIsFileExists
()
throws
Exception
{
...
...
@@ -24,7 +35,7 @@ public class FileUtilsTest {
}
@Test
public
void
testIsDir
ectory
()
throws
Exception
{
public
void
testIsDir
()
throws
Exception
{
assertThat
(
isDir
(
path
+
"UTF8.txt"
)).
isFalse
();
assertThat
(
isDir
(
path
)).
isTrue
();
}
...
...
@@ -43,13 +54,128 @@ public class FileUtilsTest {
@Test
public
void
testCreateOrExistsFile
()
throws
Exception
{
assertThat
(
createOrExistsFile
(
path
+
"new
Dir"
)).
isTrue
();
assertThat
(
createOrExistsFile
(
path
+
"new
File"
)).
isTrue
();
assertThat
(
createOrExistsFile
(
path
)).
isFalse
();
}
@Test
public
void
testCreateFileByDeleteOldFile
()
throws
Exception
{
assertThat
(
createFileByDeleteOldFile
(
path
+
"new
Dir"
)).
isTrue
();
assertThat
(
createFileByDeleteOldFile
(
path
+
"new
File"
)).
isTrue
();
assertThat
(
createFileByDeleteOldFile
(
path
)).
isFalse
();
}
String
path1
=
BASEPATH
+
"file1"
+
SEP
;
@Test
public
void
testCopyDir
()
throws
Exception
{
assertThat
(
copyDir
(
path
,
path
)).
isFalse
();
assertThat
(
copyDir
(
path
,
path
+
"new Dir"
)).
isFalse
();
assertThat
(
copyDir
(
path
,
path1
)).
isTrue
();
}
@Test
public
void
testCopyFile
()
throws
Exception
{
assertThat
(
copyFile
(
path
+
"GBK.txt"
,
path
+
"GBK.txt"
)).
isFalse
();
assertThat
(
copyFile
(
path
+
"GBK.txt"
,
path
+
"new Dir"
+
SEP
+
"GBK.txt"
)).
isTrue
();
assertThat
(
copyFile
(
path
+
"GBK.txt"
,
path1
+
"GBK.txt"
)).
isTrue
();
}
@Test
public
void
testMoveDir
()
throws
Exception
{
assertThat
(
moveDir
(
path
,
path
)).
isFalse
();
assertThat
(
moveDir
(
path
,
path
+
"new Dir"
)).
isFalse
();
assertThat
(
moveDir
(
path
,
path1
)).
isTrue
();
assertThat
(
moveDir
(
path1
,
path
)).
isTrue
();
}
@Test
public
void
testMoveFile
()
throws
Exception
{
assertThat
(
moveFile
(
path
+
"GBK.txt"
,
path
+
"GBK.txt"
)).
isFalse
();
assertThat
(
moveFile
(
path
+
"GBK.txt"
,
path1
+
"GBK.txt"
)).
isTrue
();
assertThat
(
moveFile
(
path1
+
"GBK.txt"
,
path
+
"GBK.txt"
)).
isTrue
();
}
@Test
public
void
testDeleteDir
()
throws
Exception
{
assertThat
(
deleteDir
(
path
+
"GBK.txt"
)).
isFalse
();
assertThat
(
deleteDir
(
path
+
"del"
)).
isTrue
();
}
@Test
public
void
testDeleteFile
()
throws
Exception
{
assertThat
(
deleteFile
(
path
)).
isFalse
();
assertThat
(
deleteFile
(
path
+
"GBK1.txt"
)).
isTrue
();
assertThat
(
deleteFile
(
path
+
"del.txt"
)).
isTrue
();
}
@Test
public
void
testWriteFileFromIS
()
throws
Exception
{
assertThat
(
writeFileFromIS
(
path
+
"NEW.txt"
,
new
FileInputStream
(
path
+
"UTF8.txt"
),
false
))
.
isTrue
();
assertThat
(
writeFileFromIS
(
path
+
"NEW.txt"
,
new
FileInputStream
(
path
+
"UTF8.txt"
),
true
))
.
isTrue
();
}
@Test
public
void
testWriteFileFromString
()
throws
Exception
{
assertThat
(
writeFileFromString
(
path
+
"NEW.txt"
,
"这是新的"
,
false
)).
isTrue
();
assertThat
(
writeFileFromString
(
path
+
"NEW.txt"
,
"\r\n这是追加的"
,
true
)).
isTrue
();
}
@Test
public
void
testGetFileCharsetSimple
()
throws
Exception
{
assertThat
(
getFileCharsetSimple
(
path
+
"GBK.txt"
)).
isEqualTo
(
"GBK"
);
assertThat
(
getFileCharsetSimple
(
path
+
"Unicode.txt"
)).
isEqualTo
(
"Unicode"
);
assertThat
(
getFileCharsetSimple
(
path
+
"UTF8.txt"
)).
isEqualTo
(
"UTF-8"
);
assertThat
(
getFileCharsetSimple
(
path
+
"UTF16BE.txt"
)).
isEqualTo
(
"UTF-16BE"
);
}
@Test
public
void
testGetFileLines
()
throws
Exception
{
assertThat
(
getFileLines
(
path
+
"UTF8.txt"
)).
isEqualTo
(
7
);
}
@Test
public
void
testReadFile2List
()
throws
Exception
{
System
.
out
.
println
(
readFile2List
(
path
+
"UTF8.txt"
,
""
).
toString
());
System
.
out
.
println
(
readFile2List
(
path
+
"UTF8.txt"
,
"UTF-8"
).
toString
());
System
.
out
.
println
(
readFile2List
(
path
+
"UTF8.txt"
,
"GBK"
).
toString
());
}
@Test
public
void
testReadFile2SB
()
throws
Exception
{
System
.
out
.
println
(
readFile2SB
(
path
+
"UTF8.txt"
,
""
).
toString
());
System
.
out
.
println
(
readFile2SB
(
path
+
"UTF8.txt"
,
"UTF-8"
).
toString
());
System
.
out
.
println
(
readFile2SB
(
path
+
"UTF8.txt"
,
"GBK"
).
toString
());
}
@Test
public
void
testByte2Unit
()
throws
Exception
{
assertThat
(
byte2Unit
(
ConstUtils
.
GB
,
ConstUtils
.
MB
)
-
1024
).
isWithin
(
0.001
);
}
@Test
public
void
testGetFileSize
()
throws
Exception
{
assertThat
(
getFileSize
(
path
+
"UTF8.txt"
,
ConstUtils
.
BYTE
)
-
25
).
isWithin
(
0.001
);
}
@Test
public
void
testGetDirName
()
throws
Exception
{
assertThat
(
getDirName
(
path
+
"UTF8.txt"
)).
isEqualTo
(
path
);
}
@Test
public
void
testGetFileName
()
throws
Exception
{
assertThat
(
getFileName
(
path
+
"UTF8.txt"
)).
isEqualTo
(
"UTF8.txt"
);
}
@Test
public
void
testGetFileNameNoExtension
()
throws
Exception
{
assertThat
(
getFileNameNoExtension
(
path
+
"UTF8.txt"
)).
isEqualTo
(
"UTF8"
);
}
@Test
public
void
testGetFileExtension
()
throws
Exception
{
assertThat
(
getFileExtension
(
path
+
"UTF8.txt"
)).
isEqualTo
(
"txt"
);
}
}
\ No newline at end of file
utilcode/src/test/java/com/blankj/utilcode/utils/TestUtils.java
0 → 100644
浏览文件 @
94fe6911
package
com.blankj.utilcode.utils
;
import
java.io.File
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/21
* desc : 单元测试工具类
* </pre>
*/
public
class
TestUtils
{
private
TestUtils
()
{
throw
new
UnsupportedOperationException
(
"u can't fuck me..."
);
}
public
static
final
char
SEP
=
File
.
separatorChar
;
public
static
final
String
BASEPATH
=
System
.
getProperty
(
"user.dir"
)
+
SEP
+
"src"
+
SEP
+
"test"
+
SEP
+
"res"
+
SEP
;
}
utilcode/src/test/res/MD5.txt
→
utilcode/src/test/res/
encrypt/
MD5.txt
浏览文件 @
94fe6911
文件已移动
utilcode/src/test/res/GBK.txt
→
utilcode/src/test/res/
file/
GBK.txt
浏览文件 @
94fe6911
文件已移动
utilcode/src/test/res/UTF16BE.txt
→
utilcode/src/test/res/
file/
UTF16BE.txt
浏览文件 @
94fe6911
文件已移动
utilcode/src/test/res/UTF8.txt
→
utilcode/src/test/res/
file/
UTF8.txt
浏览文件 @
94fe6911
文件已移动
utilcode/src/test/res/Unicode.txt
→
utilcode/src/test/res/
file/
Unicode.txt
浏览文件 @
94fe6911
文件已移动
utilcode/src/test/res/new Dir
已删除
100644 → 0
浏览文件 @
954b97fc
utilcode/utilcode.iml
浏览文件 @
94fe6911
...
...
@@ -65,14 +65,6 @@
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/jni"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/rs"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/shaders"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/res"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/resources"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/assets"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/aidl"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/java"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/jni"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/rs"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/shaders"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/res"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/resources"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/assets"
type=
"java-test-resource"
/>
...
...
@@ -81,6 +73,14 @@
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/jni"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/rs"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/shaders"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/res"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/resources"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/assets"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/aidl"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/java"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/jni"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/rs"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/shaders"
isTestSource=
"true"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/build/docs"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/build/intermediates/assets"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/build/intermediates/blame"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录