Skip to content

Commit ea06bc9

Browse files
author
Blankj
committed
see 06/14 log
1 parent 5239b8e commit ea06bc9

6 files changed

Lines changed: 31 additions & 22 deletions

File tree

README-CN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ readFile2String : 读取文件到字符串中
192192
readFile2BytesByStream : 读取文件到字节数组中
193193
readFile2BytesByChannel : 读取文件到字节数组中
194194
readFile2BytesByMap : 读取文件到字节数组中
195+
setBufferSize : 设置缓冲区尺寸
195196
```
196197

197198
* ### 文件相关→[FileUtils.java][file.java][Test][file.test]
@@ -662,7 +663,7 @@ getEntries : 获取压缩文件中的文件对象
662663

663664
Gradle:
664665
``` groovy
665-
compile 'com.blankj:utilcode:1.7.0'
666+
compile 'com.blankj:utilcode:1.7.1'
666667
```
667668

668669

@@ -684,7 +685,7 @@ Utils.init(context);
684685

685686

686687

687-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.7.0-brightgreen.svg
688+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.7.1-brightgreen.svg
688689
[auc]: https://github.com/Blankj/AndroidUtilCode
689690

690691
[apisvg]: https://img.shields.io/badge/API-15+-brightgreen.svg

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ readFile2String
192192
readFile2BytesByStream
193193
readFile2BytesByChannel
194194
readFile2BytesByMap
195+
setBufferSize
195196
```
196197

197198
* ### About File→[FileUtils.java][file.java][Test][file.test]
@@ -662,7 +663,7 @@ getEntries
662663

663664
Gradle:
664665
``` groovy
665-
compile 'com.blankj:utilcode:1.7.0'
666+
compile 'com.blankj:utilcode:1.7.1'
666667
```
667668

668669

@@ -684,7 +685,7 @@ Utils.init(context);
684685

685686

686687

687-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.7.0-brightgreen.svg
688+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.7.1-brightgreen.svg
688689
[auc]: https://github.com/Blankj/AndroidUtilCode
689690

690691
[apisvg]: https://img.shields.io/badge/API-15+-brightgreen.svg

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.blankj.androidutilcode"
1111
minSdkVersion 15
1212
targetSdkVersion 16
13-
versionCode 40
14-
versionName "1.7.0"
13+
versionCode 41
14+
versionName "1.7.1"
1515
}
1616

1717
if (signPropertiesFile.exists()) {

utilcode/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ android {
2626

2727
defaultConfig {
2828
minSdkVersion 15
29-
versionCode 40
30-
versionName "1.7.0"
29+
versionCode 41
30+
versionName "1.7.1"
3131
}
3232

3333
buildTypes {

utilcode/src/main/java/com/blankj/utilcode/util/FileIOUtils.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.blankj.utilcode.util;
22

3-
import com.blankj.utilcode.constant.MemoryConstants;
4-
53
import java.io.BufferedOutputStream;
64
import java.io.BufferedReader;
75
import java.io.BufferedWriter;
@@ -37,6 +35,8 @@ private FileIOUtils() {
3735

3836
private static final String LINE_SEP = System.getProperty("line.separator");
3937

38+
private static int sBufferSize = 8192;
39+
4040
/**
4141
* 将输入流写入文件
4242
*
@@ -84,9 +84,9 @@ public static boolean writeFileFromIS(File file, final InputStream is, boolean a
8484
OutputStream os = null;
8585
try {
8686
os = new BufferedOutputStream(new FileOutputStream(file, append));
87-
byte data[] = new byte[1024];
87+
byte data[] = new byte[sBufferSize];
8888
int len;
89-
while ((len = is.read(data, 0, 1024)) != -1) {
89+
while ((len = is.read(data, 0, sBufferSize)) != -1) {
9090
os.write(data, 0, len);
9191
}
9292
return true;
@@ -543,9 +543,9 @@ public static byte[] readFile2BytesByStream(File file) {
543543
try {
544544
fis = new FileInputStream(file);
545545
os = new ByteArrayOutputStream();
546-
byte[] b = new byte[MemoryConstants.KB];
546+
byte[] b = new byte[sBufferSize];
547547
int len;
548-
while ((len = fis.read(b, 0, MemoryConstants.KB)) != -1) {
548+
while ((len = fis.read(b, 0, sBufferSize)) != -1) {
549549
os.write(b, 0, len);
550550
}
551551
return os.toByteArray();
@@ -625,6 +625,15 @@ public static byte[] readFile2BytesByMap(File file) {
625625
}
626626
}
627627

628+
/**
629+
* 设置缓冲区尺寸
630+
*
631+
* @param bufferSize 缓冲区大小
632+
*/
633+
public static void setBufferSize(int bufferSize) {
634+
FileIOUtils.sBufferSize = bufferSize;
635+
}
636+
628637
private static boolean isSpace(String s) {
629638
if (s == null) return true;
630639
for (int i = 0, len = s.length(); i < len; ++i) {

utilcode/src/main/java/com/blankj/utilcode/util/FileUtils.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import android.annotation.SuppressLint;
44

5-
import com.blankj.utilcode.constant.MemoryConstants;
6-
75
import java.io.BufferedInputStream;
86
import java.io.File;
97
import java.io.FileInputStream;
@@ -1112,14 +1110,14 @@ private static String bytes2HexString(byte[] bytes) {
11121110
private static String byte2FitMemorySize(long byteNum) {
11131111
if (byteNum < 0) {
11141112
return "shouldn't be less than zero!";
1115-
} else if (byteNum < MemoryConstants.KB) {
1113+
} else if (byteNum < 1024) {
11161114
return String.format("%.3fB", (double) byteNum + 0.0005);
1117-
} else if (byteNum < MemoryConstants.MB) {
1118-
return String.format("%.3fKB", (double) byteNum / MemoryConstants.KB + 0.0005);
1119-
} else if (byteNum < MemoryConstants.GB) {
1120-
return String.format("%.3fMB", (double) byteNum / MemoryConstants.MB + 0.0005);
1115+
} else if (byteNum < 1048576) {
1116+
return String.format("%.3fKB", (double) byteNum / 1024 + 0.0005);
1117+
} else if (byteNum < 1073741824) {
1118+
return String.format("%.3fMB", (double) byteNum / 1048576 + 0.0005);
11211119
} else {
1122-
return String.format("%.3fGB", (double) byteNum / MemoryConstants.GB + 0.0005);
1120+
return String.format("%.3fGB", (double) byteNum / 1073741824 + 0.0005);
11231121
}
11241122
}
11251123

0 commit comments

Comments
 (0)