88 System.err.println("Warning: setLastModified on directories "
89 + "not supported");
90 }
91 }
92
93 if (f.exists()) {
94 if (!f.delete())
95 throw new Exception("Can't delete test file " + f);
96 }
97 if (f.setLastModified(nt))
98 throw new Exception("Succeeded on non-existent file: " + f);
99
100 // set/check last modified on files of size 1, 1GB+1, 2GB+1, ..
101 // On Windows we only test with a tiny file as that platform doesn't
102 // support sparse files by default and so the test takes too long.
103 final long G = 1024L * 1024L * 1024L;
104 final long MAX_POSITION =
105 System.getProperty("os.name").startsWith("Windows") ? 0L : 3L*G;
106 long pos = 0L;
107 while (pos <= MAX_POSITION) {
108 FileChannel fc = new FileOutputStream(f).getChannel();
109 fc.position(pos).write(ByteBuffer.wrap("x".getBytes()));
110 fc.close();
111 ot = f.lastModified();
112 System.out.format("check with file size: %d\n", f.length());
113 if (!f.setLastModified(nt))
114 throw new Exception("setLastModified failed on file: " + f);
115 ck(f, nt, f.lastModified());
116 pos += G;
117 }
118
119 if (!f.delete()) throw new Exception("Can't delete test file " + f);
120 if (!d2.delete()) throw new Exception("Can't delete test directory " + d2);
121 }
122
123 }
|
88 System.err.println("Warning: setLastModified on directories "
89 + "not supported");
90 }
91 }
92
93 if (f.exists()) {
94 if (!f.delete())
95 throw new Exception("Can't delete test file " + f);
96 }
97 if (f.setLastModified(nt))
98 throw new Exception("Succeeded on non-existent file: " + f);
99
100 // set/check last modified on files of size 1, 1GB+1, 2GB+1, ..
101 // On Windows we only test with a tiny file as that platform doesn't
102 // support sparse files by default and so the test takes too long.
103 final long G = 1024L * 1024L * 1024L;
104 final long MAX_POSITION =
105 System.getProperty("os.name").startsWith("Windows") ? 0L : 3L*G;
106 long pos = 0L;
107 while (pos <= MAX_POSITION) {
108 try (FileChannel fc = new FileOutputStream(f).getChannel()) {
109 fc.position(pos).write(ByteBuffer.wrap("x".getBytes()));
110 }
111 ot = f.lastModified();
112 System.out.format("check with file size: %d\n", f.length());
113 if (!f.setLastModified(nt))
114 throw new Exception("setLastModified failed on file: " + f);
115 ck(f, nt, f.lastModified());
116 pos += G;
117 }
118
119 if (!f.delete()) throw new Exception("Can't delete test file " + f);
120 if (!d2.delete()) throw new Exception("Can't delete test directory " + d2);
121 }
122
123 }
|