Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
a3872eb2
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,发现更多精彩内容 >>
提交
a3872eb2
编写于
8月 09, 2019
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 08/09 log
上级
6e27c6ec
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
235 addition
and
35 deletion
+235
-35
art/auc_frame.png
art/auc_frame.png
+0
-0
buildSrc/src/main/groovy/GLog.groovy
buildSrc/src/main/groovy/GLog.groovy
+2
-0
lib/subutil/README-CN.md
lib/subutil/README-CN.md
+1
-0
lib/subutil/README.md
lib/subutil/README.md
+1
-0
lib/utilcode/README-CN.md
lib/utilcode/README-CN.md
+2
-2
lib/utilcode/README.md
lib/utilcode/README.md
+2
-2
lib/utilcode/src/main/java/com/blankj/utilcode/util/FileIOUtils.java
...e/src/main/java/com/blankj/utilcode/util/FileIOUtils.java
+202
-31
lib/utilcode/src/main/java/com/blankj/utilcode/util/FileUtils.java
...ode/src/main/java/com/blankj/utilcode/util/FileUtils.java
+25
-0
未找到文件。
art/auc_frame.png
查看替换文件 @
6e27c6ec
浏览文件 @
a3872eb2
63.1 KB
|
W:
|
H:
65.3 KB
|
W:
|
H:
2-up
Swipe
Onion skin
buildSrc/src/main/groovy/GLog.groovy
浏览文件 @
a3872eb2
import
org.gradle.internal.impldep.org.apache.http.util.EntityUtils
/**
* <pre>
* author: blankj
...
...
lib/subutil/README-CN.md
浏览文件 @
a3872eb2
...
...
@@ -48,6 +48,7 @@ reboot : 重启
reboot2Recovery : 重启到 recovery
reboot2Bootloader : 重启到 bootloader
setMobileDataEnabled: 打开或关闭移动数据
sendSmsSilent : 发送短信
```
*
### 定位相关 ->
[
LocationUtils.java
][
location.java
]
->
[
Demo
][
location.demo
]
...
...
lib/subutil/README.md
浏览文件 @
a3872eb2
...
...
@@ -48,6 +48,7 @@ reboot
reboot2Recovery
reboot2Bootloader
setMobileDataEnabled
sendSmsSilent
```
*
### About Location ->
[
LocationUtils.java
][
location.java
]
->
[
Demo
][
location.demo
]
...
...
lib/utilcode/README-CN.md
浏览文件 @
a3872eb2
...
...
@@ -22,6 +22,7 @@ startActivities : 启动多个 Activity
startHomeActivity : 回到桌面
getActivityList : 获取 Activity 栈链表
getLauncherActivity : 获取启动项 Activity
getMainActivities : 获取主的 Activity 们
getTopActivity : 获取栈顶 Activity
isActivityAlive : 判断 Activity 是否存活
isActivityExistsInStack : 判断 Activity 是否存在栈中
...
...
@@ -394,6 +395,7 @@ getDirName : 根据全路径获取最长目录
getFileName : 根据全路径获取文件名
getFileNameNoExtension : 根据全路径获取文件名不带拓展名
getFileExtension : 根据全路径获取文件拓展名
notifySystemToScan : 通知系统扫描文件
```
*
### Fragment 相关 ->
[
FragmentUtils.java
][
fragment.java
]
->
[
Demo
][
fragment.demo
]
...
...
@@ -650,11 +652,9 @@ getPhoneType : 获取移动终端类型
isSimCardReady : 判断 sim 卡是否准备好
getSimOperatorName : 获取 Sim 卡运营商名称
getSimOperatorByMnc: 获取 Sim 卡运营商名称
getPhoneStatus : 获取手机状态信息
dial : 跳至拨号界面
call : 拨打 phoneNumber
sendSms : 跳至发送短信界面
sendSmsSilent : 发送短信
```
*
### 进程相关 ->
[
ProcessUtils.java
][
process.java
]
->
[
Demo
][
process.demo
]
...
...
lib/utilcode/README.md
浏览文件 @
a3872eb2
...
...
@@ -22,6 +22,7 @@ startActivities
startHomeActivity
getActivityList
getLauncherActivity
getMainActivities
getTopActivity
isActivityAlive
isActivityExistsInStack
...
...
@@ -394,6 +395,7 @@ getDirName
getFileName
getFileNameNoExtension
getFileExtension
notifySystemToScan
```
*
### About Fragment ->
[
FragmentUtils.java
][
fragment.java
]
->
[
Demo
][
fragment.demo
]
...
...
@@ -650,11 +652,9 @@ getPhoneType
isSimCardReady
getSimOperatorName
getSimOperatorByMnc
getPhoneStatus
dial
call
sendSms
sendSmsSilent
```
*
### About Process ->
[
ProcessUtils.java
][
process.java
]
->
[
Demo
][
process.demo
]
...
...
lib/utilcode/src/main/java/com/blankj/utilcode/util/FileIOUtils.java
浏览文件 @
a3872eb2
package
com.blankj.utilcode.util
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -37,6 +39,10 @@ public final class FileIOUtils {
throw
new
UnsupportedOperationException
(
"u can't instantiate me..."
);
}
///////////////////////////////////////////////////////////////////////////
// writeFileFromIS without progress
///////////////////////////////////////////////////////////////////////////
/**
* Write file from input stream.
*
...
...
@@ -45,7 +51,7 @@ public final class FileIOUtils {
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromIS
(
final
String
filePath
,
final
InputStream
is
)
{
return
writeFileFromIS
(
getFileByPath
(
filePath
),
is
,
false
);
return
writeFileFromIS
(
getFileByPath
(
filePath
),
is
,
false
,
null
);
}
/**
...
...
@@ -59,7 +65,7 @@ public final class FileIOUtils {
public
static
boolean
writeFileFromIS
(
final
String
filePath
,
final
InputStream
is
,
final
boolean
append
)
{
return
writeFileFromIS
(
getFileByPath
(
filePath
),
is
,
append
);
return
writeFileFromIS
(
getFileByPath
(
filePath
),
is
,
append
,
null
);
}
/**
...
...
@@ -70,7 +76,7 @@ public final class FileIOUtils {
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromIS
(
final
File
file
,
final
InputStream
is
)
{
return
writeFileFromIS
(
file
,
is
,
false
);
return
writeFileFromIS
(
file
,
is
,
false
,
null
);
}
/**
...
...
@@ -84,13 +90,88 @@ public final class FileIOUtils {
public
static
boolean
writeFileFromIS
(
final
File
file
,
final
InputStream
is
,
final
boolean
append
)
{
if
(!
createOrExistsFile
(
file
)
||
is
==
null
)
return
false
;
return
writeFileFromIS
(
file
,
is
,
append
,
null
);
}
///////////////////////////////////////////////////////////////////////////
// writeFileFromIS with progress
///////////////////////////////////////////////////////////////////////////
/**
* Write file from input stream.
*
* @param filePath The path of file.
* @param is The input stream.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromIS
(
final
String
filePath
,
final
InputStream
is
,
final
OnProgressUpdateListener
listener
)
{
return
writeFileFromIS
(
getFileByPath
(
filePath
),
is
,
false
,
listener
);
}
/**
* Write file from input stream.
*
* @param filePath The path of file.
* @param is The input stream.
* @param append True to append, false otherwise.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromIS
(
final
String
filePath
,
final
InputStream
is
,
final
boolean
append
,
final
OnProgressUpdateListener
listener
)
{
return
writeFileFromIS
(
getFileByPath
(
filePath
),
is
,
append
,
listener
);
}
/**
* Write file from input stream.
*
* @param file The file.
* @param is The input stream.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromIS
(
final
File
file
,
final
InputStream
is
,
final
OnProgressUpdateListener
listener
)
{
return
writeFileFromIS
(
file
,
is
,
false
,
listener
);
}
/**
* Write file from input stream.
*
* @param file The file.
* @param is The input stream.
* @param append True to append, false otherwise.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromIS
(
final
File
file
,
final
InputStream
is
,
final
boolean
append
,
final
OnProgressUpdateListener
listener
)
{
if
(
is
==
null
||
!
createOrExistsFile
(
file
))
return
false
;
OutputStream
os
=
null
;
try
{
os
=
new
BufferedOutputStream
(
new
FileOutputStream
(
file
,
append
));
byte
data
[]
=
new
byte
[
sBufferSize
];
for
(
int
len
;
(
len
=
is
.
read
(
data
))
!=
-
1
;
)
{
os
.
write
(
data
,
0
,
len
);
os
=
new
BufferedOutputStream
(
new
FileOutputStream
(
file
,
append
),
sBufferSize
);
if
(
listener
==
null
)
{
byte
[]
data
=
new
byte
[
sBufferSize
];
for
(
int
len
;
(
len
=
is
.
read
(
data
))
!=
-
1
;
)
{
os
.
write
(
data
,
0
,
len
);
}
}
else
{
double
totalSize
=
is
.
available
();
int
curSize
=
0
;
listener
.
onProgressUpdate
(
0
);
byte
[]
data
=
new
byte
[
sBufferSize
];
for
(
int
len
;
(
len
=
is
.
read
(
data
))
!=
-
1
;
)
{
os
.
write
(
data
,
0
,
len
);
listener
.
onProgressUpdate
(
curSize
/
totalSize
);
}
}
return
true
;
}
catch
(
IOException
e
)
{
...
...
@@ -112,6 +193,11 @@ public final class FileIOUtils {
}
}
///////////////////////////////////////////////////////////////////////////
// writeFileFromBytesByStream without progress
///////////////////////////////////////////////////////////////////////////
/**
* Write file from bytes by stream.
*
...
...
@@ -120,7 +206,7 @@ public final class FileIOUtils {
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromBytesByStream
(
final
String
filePath
,
final
byte
[]
bytes
)
{
return
writeFileFromBytesByStream
(
getFileByPath
(
filePath
),
bytes
,
false
);
return
writeFileFromBytesByStream
(
getFileByPath
(
filePath
),
bytes
,
false
,
null
);
}
/**
...
...
@@ -134,7 +220,7 @@ public final class FileIOUtils {
public
static
boolean
writeFileFromBytesByStream
(
final
String
filePath
,
final
byte
[]
bytes
,
final
boolean
append
)
{
return
writeFileFromBytesByStream
(
getFileByPath
(
filePath
),
bytes
,
append
);
return
writeFileFromBytesByStream
(
getFileByPath
(
filePath
),
bytes
,
append
,
null
);
}
/**
...
...
@@ -145,7 +231,7 @@ public final class FileIOUtils {
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromBytesByStream
(
final
File
file
,
final
byte
[]
bytes
)
{
return
writeFileFromBytesByStream
(
file
,
bytes
,
false
);
return
writeFileFromBytesByStream
(
file
,
bytes
,
false
,
null
);
}
/**
...
...
@@ -159,26 +245,79 @@ public final class FileIOUtils {
public
static
boolean
writeFileFromBytesByStream
(
final
File
file
,
final
byte
[]
bytes
,
final
boolean
append
)
{
if
(
bytes
==
null
||
!
createOrExistsFile
(
file
))
return
false
;
BufferedOutputStream
bos
=
null
;
try
{
bos
=
new
BufferedOutputStream
(
new
FileOutputStream
(
file
,
append
));
bos
.
write
(
bytes
);
return
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
finally
{
try
{
if
(
bos
!=
null
)
{
bos
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
writeFileFromBytesByStream
(
file
,
bytes
,
append
,
null
);
}
///////////////////////////////////////////////////////////////////////////
// writeFileFromBytesByStream with progress
///////////////////////////////////////////////////////////////////////////
/**
* Write file from bytes by stream.
*
* @param filePath The path of file.
* @param bytes The bytes.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromBytesByStream
(
final
String
filePath
,
final
byte
[]
bytes
,
final
OnProgressUpdateListener
listener
)
{
return
writeFileFromBytesByStream
(
getFileByPath
(
filePath
),
bytes
,
false
,
listener
);
}
/**
* Write file from bytes by stream.
*
* @param filePath The path of file.
* @param bytes The bytes.
* @param append True to append, false otherwise.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromBytesByStream
(
final
String
filePath
,
final
byte
[]
bytes
,
final
boolean
append
,
final
OnProgressUpdateListener
listener
)
{
return
writeFileFromBytesByStream
(
getFileByPath
(
filePath
),
bytes
,
append
,
listener
);
}
/**
* Write file from bytes by stream.
*
* @param file The file.
* @param bytes The bytes.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromBytesByStream
(
final
File
file
,
final
byte
[]
bytes
,
final
OnProgressUpdateListener
listener
)
{
return
writeFileFromBytesByStream
(
file
,
bytes
,
false
,
listener
);
}
/**
* Write file from bytes by stream.
*
* @param file The file.
* @param bytes The bytes.
* @param append True to append, false otherwise.
* @param listener The progress update listener.
* @return {@code true}: success<br>{@code false}: fail
*/
public
static
boolean
writeFileFromBytesByStream
(
final
File
file
,
final
byte
[]
bytes
,
final
boolean
append
,
final
OnProgressUpdateListener
listener
)
{
if
(
bytes
==
null
)
return
false
;
return
writeFileFromIS
(
file
,
new
ByteArrayInputStream
(
bytes
),
append
,
listener
);
}
///////////////////////////////////////////////////////////////////////////
// writeFileFromBytesByChannel
///////////////////////////////////////////////////////////////////////////
/**
* Write file from bytes by channel.
*
...
...
@@ -236,7 +375,7 @@ public final class FileIOUtils {
final
byte
[]
bytes
,
final
boolean
append
,
final
boolean
isForce
)
{
if
(
bytes
==
null
)
return
false
;
if
(
bytes
==
null
||
!
createOrExistsFile
(
file
)
)
return
false
;
FileChannel
fc
=
null
;
try
{
fc
=
new
FileOutputStream
(
file
,
append
).
getChannel
();
...
...
@@ -610,7 +749,33 @@ public final class FileIOUtils {
public
static
byte
[]
readFile2BytesByStream
(
final
File
file
)
{
if
(!
isFileExists
(
file
))
return
null
;
try
{
return
is2Bytes
(
new
FileInputStream
(
file
));
ByteArrayOutputStream
os
=
null
;
InputStream
is
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
try
{
os
=
new
ByteArrayOutputStream
();
byte
[]
b
=
new
byte
[
sBufferSize
];
int
len
;
while
((
len
=
is
.
read
(
b
,
0
,
sBufferSize
))
!=
-
1
)
{
os
.
write
(
b
,
0
,
len
);
}
return
os
.
toByteArray
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
finally
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
if
(
os
!=
null
)
{
os
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
return
null
;
...
...
@@ -778,4 +943,10 @@ public final class FileIOUtils {
}
}
}
public
interface
OnProgressUpdateListener
{
void
onProgressUpdate
(
double
progress
);
}
}
lib/utilcode/src/main/java/com/blankj/utilcode/util/FileUtils.java
浏览文件 @
a3872eb2
package
com.blankj.utilcode.util
;
import
android.content.Intent
;
import
android.net.Uri
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
...
...
@@ -1184,6 +1187,28 @@ public final class FileUtils {
return
filePath
.
substring
(
lastPoi
+
1
);
}
/**
* Notify system to scan the file.
*
* @param file The file.
*/
public
static
void
notifySystemToScan
(
final
File
file
)
{
if
(
file
==
null
||
!
file
.
exists
())
return
;
Intent
intent
=
new
Intent
(
Intent
.
ACTION_MEDIA_SCANNER_SCAN_FILE
);
Uri
uri
=
Uri
.
fromFile
(
file
);
intent
.
setData
(
uri
);
Utils
.
getApp
().
sendBroadcast
(
intent
);
}
/**
* Notify system to scan the file.
*
* @param filePath The path of file.
*/
public
static
void
notifySystemToScan
(
final
String
filePath
)
{
notifySystemToScan
(
getFileByPath
(
filePath
));
}
///////////////////////////////////////////////////////////////////////////
// interface
///////////////////////////////////////////////////////////////////////////
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录