see 08/23 log · ttylinux/AndroidUtilCode@dd2193e · GitHub
Skip to content

Commit dd2193e

Browse files
author
blankj
committed
see 08/23 log
1 parent 7ec95e8 commit dd2193e

6 files changed

Lines changed: 91 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
###
2+
#### 16/08/23 小修bug,接下来完善SDCardUtils和ImageUtils
23
#### 16/08/22 SPUtils将commit改为apply提高效率,将SPUtils改为构造函数法创建,FileUtils新增查找函数,规范JavaDoc
34
#### 16/08/21 FileUtils单元测试完毕,修复FileUtils的bug,发布版本1.1.2
45
#### 16/08/20 更新目录,继续完善FileUtils单元测试,发布版本1.1.1

utilcode/src/main/java/com/blankj/utilcode/utils/ConvertUtils.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.blankj.utilcode.utils;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
38
/**
49
* <pre>
510
* author: Blankj
@@ -95,4 +100,38 @@ public static char[] bytes2Chars(byte[] bytes) {
95100
}
96101
return chars;
97102
}
103+
104+
/**
105+
* 将输入流转为字节数组
106+
*
107+
* @param is 输入流
108+
* @return 字节数组
109+
*/
110+
public static byte[] inputStream2Bytes(InputStream is) {
111+
if (is == null) return null;
112+
try {
113+
ByteArrayOutputStream os = new ByteArrayOutputStream();
114+
byte[] b = new byte[ConstUtils.KB];
115+
int len;
116+
while ((len = is.read(b)) != -1) {
117+
os.write(b, 0, len);
118+
}
119+
return os.toByteArray();
120+
} catch (IOException e) {
121+
e.printStackTrace();
122+
return null;
123+
} finally {
124+
FileUtils.closeIO(is);
125+
}
126+
}
127+
128+
/**
129+
* 将字节数组转为输入流
130+
*
131+
* @param bytes 字节数组
132+
* @return 输入流
133+
*/
134+
public static InputStream bytes2InputStream(byte[] bytes) {
135+
return new ByteArrayInputStream(bytes);
136+
}
98137
}

utilcode/src/main/java/com/blankj/utilcode/utils/SDCardUtils.java

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

3+
import android.content.Context;
34
import android.os.Environment;
45

56
import java.io.File;
@@ -37,6 +38,10 @@ public static String getSDCardPath() {
3738
return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
3839
}
3940

41+
public static String getSDCardCacheDir(Context context){
42+
return context.getExternalCacheDir().getPath();
43+
}
44+
4045
// /**
4146
// * 计算SD卡的剩余空间
4247
// *
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.blankj.utilcode.utils;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.robolectric.RobolectricTestRunner;
6+
import org.robolectric.annotation.Config;
7+
8+
/**
9+
* <pre>
10+
* author: Blankj
11+
* blog : http://blankj.com
12+
* time : 2016/8/23
13+
* desc : SDCard单元测试
14+
* </pre>
15+
*/
16+
@RunWith(RobolectricTestRunner.class)
17+
@Config(manifest = Config.NONE)
18+
public class SDCardUtilsTest {
19+
20+
@Test
21+
public void testIsSDCardEnable() throws Exception {
22+
System.out.println(SDCardUtils.isSDCardEnable());
23+
}
24+
25+
@Test
26+
public void testGetSDCardPath() throws Exception {
27+
System.out.println(SDCardUtils.getSDCardPath());
28+
}
29+
}

utilcode/utilcode.iml

Lines changed: 16 additions & 16 deletions

0 commit comments

Comments
 (0)