提交 a3872eb2 编写于 作者: B Blankj

see 08/09 log

上级 6e27c6ec
art/auc_frame.png

63.1 KB | W: | H:

art/auc_frame.png

65.3 KB | W: | H:

art/auc_frame.png
art/auc_frame.png
art/auc_frame.png
art/auc_frame.png
  • 2-up
  • Swipe
  • Onion skin
import org.gradle.internal.impldep.org.apache.http.util.EntityUtils
/**
* <pre>
* author: blankj
......
......@@ -48,6 +48,7 @@ reboot : 重启
reboot2Recovery : 重启到 recovery
reboot2Bootloader : 重启到 bootloader
setMobileDataEnabled: 打开或关闭移动数据
sendSmsSilent : 发送短信
```
* ### 定位相关 -> [LocationUtils.java][location.java] -> [Demo][location.demo]
......
......@@ -48,6 +48,7 @@ reboot
reboot2Recovery
reboot2Bootloader
setMobileDataEnabled
sendSmsSilent
```
* ### About Location -> [LocationUtils.java][location.java] -> [Demo][location.demo]
......
......@@ -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]
......
......@@ -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]
......
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);
}
}
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.
先完成此消息的编辑!
想要评论请 注册