Nice/stdlib/nice/io file.nice,1.2,1.3
Bryn Keller <[email protected]>
| Newsgroups | gmane.comp.lang.nice.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/nice/Nice/stdlib/nice/io
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23336/stdlib/nice/io
Modified Files:
file.nice
Log Message:
nice.io builds and tests correctly.
Index: file.nice
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/io/file.nice,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** file.nice 4 Mar 2005 09:48:16 -0000 1.2
--- file.nice 4 Mar 2005 21:36:09 -0000 1.3
***************
*** 52,56 ****
* all subdirectories which match the filter.
*/
! void->File traverse(File dir, File->boolean filter = always(true))
requires dir.isDirectory() : "Only directories can be passed to traverse()."
{
--- 52,58 ----
* all subdirectories which match the filter.
*/
! void->File traverse(File dir, File->boolean filter = always(true),
! (File,File)->int sortBy =
! (File f, File f2) => f.compareTo(f2))
requires dir.isDirectory() : "Only directories can be passed to traverse()."
{
***************
*** 58,62 ****
//Java doesn't do tail call elimination...
let stack = new Stack();
! var current = dir.listDir(filter).iterator();
return () => {
while(!current.hasNext()) {
--- 60,66 ----
//Java doesn't do tail call elimination...
let stack = new Stack();
! var list = dir.listDir(filter).toArrayList();
! list.sort(sortBy);
! var current = list.iterator();
return () => {
while(!current.hasNext()) {
***************
*** 70,74 ****
if (f.isDirectory()) {
stack.push(current);
! current = f.listDir(filter).iterator();
}
return f;
--- 74,80 ----
if (f.isDirectory()) {
stack.push(current);
! list = f.listDir(filter).toArrayList();
! list.sort(sortBy);
! current = list.iterator();
}
return f;
***************
*** 134,138 ****
new java.io.FileInputStream(file), encoding)
);
! void close() { input.close(); stop(); }
return ()=> {
try {
--- 140,144 ----
new java.io.FileInputStream(file), encoding)
);
! String close() { input.close(); return stop(); }
return ()=> {
try {
***************
*** 146,149 ****
--- 152,183 ----
/**
+ * Writes all the lines yielded by the <code>lines</code> parameter
+ * to a file.
+ */
+ void writeLines(File file, void->String lines, ?String encoding = null)
+ {
+ using(let writer = new java.io.BufferedWriter(
+ (encoding == null)
+ ? new java.io.FileWriter(file)
+ : new java.io.OutputStreamWriter(
+ new java.io.FileOutputStream(file), encoding)))
+ {
+ for(line:lines.iterator())
+ {
+ writer.write(line);
+ writer.newLine();
+ }
+ }
+ }
+
+ /**
+ * Writes all the line in the list to a file.
+ */
+ void writeLines(File file, List<String> lines, ?String encoding = null)
+ {
+ file.writeLines(lines.generator());
+ }
+
+ /**
* Returns the standard temp directory.
*/
***************
*** 214,224 ****
assert res.equals(file) : "Expected " + file + " got " + res;
}
- test(tmpdir/"one"/"two");
- test(tmpdir/"one"/"two"/"three");
- test(tmpdir/"one"/"two"/"c.txt");
- test(tmpdir/"one"/"four");
- test(tmpdir/"one"/"four"/"d.txt");
test(tmpdir/"one"/"a.txt");
test(tmpdir/"one"/"b.bmp");
try {
gen();
--- 248,258 ----
assert res.equals(file) : "Expected " + file + " got " + res;
}
test(tmpdir/"one"/"a.txt");
test(tmpdir/"one"/"b.bmp");
+ test(tmpdir/"one"/"four");
+ test(tmpdir/"one"/"four"/"d.txt");
+ test(tmpdir/"one"/"two");
+ test(tmpdir/"one"/"two"/"c.txt");
+ test(tmpdir/"one"/"two"/"three");
try {
gen();
***************
*** 236,242 ****
assert res.equals(file) : "Expected " + file + " got " + res;
}
test(tmpdir/"one"/"two");
test(tmpdir/"one"/"two"/"three");
- test(tmpdir/"one"/"four");
try {
gen();
--- 270,276 ----
assert res.equals(file) : "Expected " + file + " got " + res;
}
+ test(tmpdir/"one"/"four");
test(tmpdir/"one"/"two");
test(tmpdir/"one"/"two"/"three");
try {
gen();
***************
*** 256,263 ****
assert res.equals(file) : "Expected " + file + " got " + res;
}
test(tmpdir/"one"/"two");
test(tmpdir/"one"/"two"/"three");
- test(tmpdir/"one"/"four");
- test(tmpdir/"one"/"b.bmp");
try {
gen();
--- 290,297 ----
assert res.equals(file) : "Expected " + file + " got " + res;
}
+ test(tmpdir/"one"/"b.bmp");
+ test(tmpdir/"one"/"four");
test(tmpdir/"one"/"two");
test(tmpdir/"one"/"two"/"three");
try {
gen();
***************
*** 267,270 ****
--- 301,318 ----
}
+ void _testLines()
+ {
+ let lines = ["Line 1", "Line 2", "Line 3"];
+ let f = createTempFile("_testLines", ".tmp");
+ f.writeLines(lines);
+ let lines2 = f.readLines().toList().toArray();
+ f.delete();
+ assert lines.size == lines2.size;
+ for(int i = 0; i < lines.size; i++)
+ {
+ assert lines[i].equals(lines2[i]): "Expected: " lines[i] ", got: " lines2[i];
+ }
+ }
+
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click