| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Dart test program for testing file I/O. | 5 // Dart test program for testing file I/O. |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 buffer.addAll(d); | 101 buffer.addAll(d); |
| 102 }, | 102 }, |
| 103 onDone: () { | 103 onDone: () { |
| 104 Expect.equals(42, buffer.length); | 104 Expect.equals(42, buffer.length); |
| 105 // Write the contents of the file just read into another file. | 105 // Write the contents of the file just read into another file. |
| 106 String outFilename = | 106 String outFilename = |
| 107 tempDirectory.path + "/out_read_write_stream"; | 107 tempDirectory.path + "/out_read_write_stream"; |
| 108 var file2 = new File(outFilename); | 108 var file2 = new File(outFilename); |
| 109 var output = file2.openWrite(); | 109 var output = file2.openWrite(); |
| 110 output.add(buffer); | 110 output.add(buffer); |
| 111 output.close(); | 111 output.flush().then((_) => output.close()); |
| 112 output.done.then((_) { | 112 output.done.then((_) { |
| 113 // Now read the contents of the file just written. | 113 // Now read the contents of the file just written. |
| 114 List<int> buffer2 = new List<int>(); | 114 List<int> buffer2 = new List<int>(); |
| 115 new File(outFilename).openRead().listen( | 115 new File(outFilename).openRead().listen( |
| 116 (d) { | 116 (d) { |
| 117 buffer2.addAll(d); | 117 buffer2.addAll(d); |
| 118 }, | 118 }, |
| 119 onDone: () { | 119 onDone: () { |
| 120 Expect.equals(42, buffer2.length); | 120 Expect.equals(42, buffer2.length); |
| 121 // Now compare the two buffers to check if they are | 121 // Now compare the two buffers to check if they are |
| (...skipping 18 matching lines...) Expand all Loading... |
| 140 List<int> buffer = new List<int>(100000); | 140 List<int> buffer = new List<int>(100000); |
| 141 for (var i = 0; i < buffer.length; ++i) { | 141 for (var i = 0; i < buffer.length; ++i) { |
| 142 buffer[i] = i % 256; | 142 buffer[i] = i % 256; |
| 143 } | 143 } |
| 144 String filename = | 144 String filename = |
| 145 tempDirectory.path + "/out_read_write_stream_large_file"; | 145 tempDirectory.path + "/out_read_write_stream_large_file"; |
| 146 File file = new File(filename); | 146 File file = new File(filename); |
| 147 IOSink output = file.openWrite(); | 147 IOSink output = file.openWrite(); |
| 148 output.add(buffer); | 148 output.add(buffer); |
| 149 output.add(buffer); | 149 output.add(buffer); |
| 150 output.close(); | 150 output.flush().then((_) => output.close()); |
| 151 output.done.then((_) { | 151 output.done.then((_) { |
| 152 Stream input = file.openRead(); | 152 Stream input = file.openRead(); |
| 153 int position = 0; | 153 int position = 0; |
| 154 final int expectedLength = 200000; | 154 final int expectedLength = 200000; |
| 155 // Start an independent asynchronous check on the length. | 155 // Start an independent asynchronous check on the length. |
| 156 asyncTestStarted(); | 156 asyncTestStarted(); |
| 157 file.length().then((len) { | 157 file.length().then((len) { |
| 158 Expect.equals(expectedLength, len); | 158 Expect.equals(expectedLength, len); |
| 159 asyncTestDone('testReadWriteStreamLargeFile: length check'); | 159 asyncTestDone('testReadWriteStreamLargeFile: length check'); |
| 160 }); | 160 }); |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 testLastModified(); | 1326 testLastModified(); |
| 1327 testDoubleAsyncOperation(); | 1327 testDoubleAsyncOperation(); |
| 1328 asyncEnd(); | 1328 asyncEnd(); |
| 1329 }); | 1329 }); |
| 1330 } | 1330 } |
| 1331 } | 1331 } |
| 1332 | 1332 |
| 1333 main() { | 1333 main() { |
| 1334 FileTest.testMain(); | 1334 FileTest.testMain(); |
| 1335 } | 1335 } |
| OLD | NEW |