diff options
-rw-r--r-- | luni/src/test/java/libcore/android/system/OsTest.java | 9 | ||||
-rw-r--r-- | support/src/test/java/libcore/testing/io/TestIoUtils.java | 11 |
2 files changed, 16 insertions, 4 deletions
diff --git a/luni/src/test/java/libcore/android/system/OsTest.java b/luni/src/test/java/libcore/android/system/OsTest.java index 7536885c20..dd5e6985fb 100644 --- a/luni/src/test/java/libcore/android/system/OsTest.java +++ b/luni/src/test/java/libcore/android/system/OsTest.java @@ -56,6 +56,7 @@ import java.util.concurrent.atomic.AtomicReference; import junit.framework.TestCase; import libcore.io.IoUtils; +import libcore.testing.io.TestIoUtils; import static android.system.OsConstants.*; @@ -81,7 +82,7 @@ public class OsTest extends TestCase { int flags = Os.fcntlVoid(fis.getFD(), F_GETFD); assertTrue((flags & FD_CLOEXEC) != 0); } finally { - IoUtils.closeQuietly(fis); + TestIoUtils.closeQuietly(fis); f.delete(); } } @@ -1133,7 +1134,7 @@ public class OsTest extends TestCase { } public void test_readlink() throws Exception { - File path = new File(IoUtils.createTemporaryDirectory("test_readlink"), "symlink"); + File path = new File(TestIoUtils.createTemporaryDirectory("test_readlink"), "symlink"); // ext2 and ext4 have PAGE_SIZE limits on symlink targets. // If file encryption is enabled, there's extra overhead to store the @@ -1251,7 +1252,7 @@ public class OsTest extends TestCase { android.system.Os.sendfile(outFd, inFd, offset, maxBytes); assertEquals(expectedEndOffset, offset == null ? null : offset.value); } - return IoUtils.readFileAsString(out.getPath()); + return TestIoUtils.readFileAsString(out.getPath()); } finally { out.delete(); } @@ -1307,7 +1308,7 @@ public class OsTest extends TestCase { assertEquals(5, offOut.value); } - assertEquals("oobar", IoUtils.readFileAsString(out.getPath())); + assertEquals("oobar", TestIoUtils.readFileAsString(out.getPath())); Os.close(pipe[0]); Os.close(pipe[1]); diff --git a/support/src/test/java/libcore/testing/io/TestIoUtils.java b/support/src/test/java/libcore/testing/io/TestIoUtils.java index 8e241df050..34a2cf7d4d 100644 --- a/support/src/test/java/libcore/testing/io/TestIoUtils.java +++ b/support/src/test/java/libcore/testing/io/TestIoUtils.java @@ -17,6 +17,10 @@ package libcore.testing.io; import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Random; public class TestIoUtils { @@ -25,6 +29,13 @@ public class TestIoUtils { private TestIoUtils() {} /** + * Returns the contents of 'path' as a string. The contents are assumed to be UTF-8. + */ + public static String readFileAsString(String absolutePath) throws IOException { + return new String(Files.readAllBytes(Paths.get(absolutePath)), StandardCharsets.UTF_8); + } + + /** * Creates a unique new temporary directory under "java.io.tmpdir". */ public static File createTemporaryDirectory(String prefix) { |