@@ -10,7 +10,7 @@ class FileUtilsTest {
10
10
@Test
11
11
fun deleteFile () {
12
12
val file = File .createTempFile(" testfile" , " " )
13
- writeToFile( file, " Hello, World" )
13
+ file.writeText( " Hello, World" )
14
14
15
15
assertEquals(true , file.exists())
16
16
assertEquals(true , FileUtils .deleteFile(file))
@@ -23,40 +23,22 @@ class FileUtilsTest {
23
23
24
24
assertEquals(
25
25
" 907d14fb3af2b0d4f18c2d46abe8aedce17367bd" ,
26
- fileUtilsWrapper.getSHA1(toInputStream( " Hello, World" ))
26
+ fileUtilsWrapper.getSHA1(" Hello, World" .byteInputStream( ))
27
27
)
28
28
29
29
assertEquals(
30
30
" 8b971da6347bd126872ea2f4f8d394e70c74073a" ,
31
- fileUtilsWrapper.getSHA1(toInputStream( " apps-android-commons" ))
31
+ fileUtilsWrapper.getSHA1(" apps-android-commons" .byteInputStream( ))
32
32
)
33
33
34
34
assertEquals(
35
35
" e9d30f5a3a82792b9d79c258366bd53207ceaeb3" ,
36
- fileUtilsWrapper.getSHA1(toInputStream( " domdomegg was here" ))
36
+ fileUtilsWrapper.getSHA1(" domdomegg was here" .byteInputStream( ))
37
37
)
38
38
39
39
assertEquals(
40
40
" 96e733a3e59261c0621ba99be5bd10bb21abe53e" ,
41
- fileUtilsWrapper.getSHA1(toInputStream( " iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" ))
41
+ fileUtilsWrapper.getSHA1(" iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" .byteInputStream( ))
42
42
)
43
43
}
44
-
45
- private fun writeToFile (file : File , s : String ) {
46
- val buf = BufferedOutputStream (FileOutputStream (file))
47
- buf.write(s.toByteArray())
48
- buf.close()
49
- }
50
-
51
- private fun getString (file : File ): String {
52
- val bytes = ByteArray (file.length().toInt())
53
- val buf = BufferedInputStream (FileInputStream (file))
54
- buf.read(bytes, 0 , bytes.size)
55
- buf.close()
56
- return String (bytes)
57
- }
58
-
59
- private fun toInputStream (str : String ) : InputStream {
60
- return ByteArrayInputStream (str.toByteArray(Charsets .UTF_8 ))
61
- }
62
44
}
0 commit comments