test/java/nio/file/Files/BytesAndLines.java

Print this page

        

*** 20,30 **** * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 7006126 * @summary Unit test for methods for Files readAllBytes, readAllLines and * and write methods. */ import java.nio.file.*; --- 20,30 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 7006126 8020669 * @summary Unit test for methods for Files readAllBytes, readAllLines and * and write methods. */ import java.nio.file.*;
*** 80,89 **** --- 80,99 ---- try { OpenOption[] opts = { null }; write(file, lines, Charset.defaultCharset(), opts); throw new RuntimeException("NullPointerException expected"); } catch (NullPointerException ignore) { } + + // read from procfs + if (System.getProperty("os.name").equals("Linux")) { + // Refer to the Linux proc(5) man page for details about /proc/self/stat file + // procfs reports it to be zero sized, even though data can be read from it + String statFile = "/proc/self/stat"; + Path pathStat = Paths.get(statFile); + byte[] data = Files.readAllBytes(pathStat); + assertTrue(data.length > 0, "Files.readAllBytes('" + statFile + "') failed to read"); + } } static void testReadAndWriteBytes(int size) throws IOException { Path path = createTempFile("blah", null);
*** 172,181 **** --- 182,201 ---- try { readAllLines(tmpfile, null); throw new RuntimeException("NullPointerException expected"); } catch (NullPointerException ignore) { } + // read from procfs + if (System.getProperty("os.name").equals("Linux")) { + // Refer to the Linux proc(5) man page for details about /proc/self/status file + // procfs reports this file to be zero sized, even though data can be read from it + String statusFile = "/proc/self/status"; + Path pathStatus = Paths.get(statusFile); + lines = Files.readAllLines(pathStatus, US_ASCII); + assertTrue(lines.size() > 0, "Files.readAllLines('" + pathStatus + "') failed to read"); + } + } finally { delete(tmpfile); } }
*** 240,250 **** } catch (NullPointerException ignore) { } } finally { delete(tmpfile); } - } static void assertTrue(boolean expr, String errmsg) { if (!expr) throw new RuntimeException(errmsg); --- 260,269 ----